Is there a way to print out a string on the same line after the user has input their name and hit enter? Not sure if its possible with scanner so any input on other solutions is helpful.
Example.
Scanner sc = new Scanner(System.in);
System.out.println("Enter your name:");
String name = sc.nextLine();
System.out.print(" Hello" + name);
Current Console Output:
Enter your name:
Dylan
Hello Dylan
Desired Console Output:
Enter your name:
Dylan Hello Dylan
I have tried changing print
to println
and vice versa but it seems to me like .nextLine()
or something else with the scanner class itself is inserting a new line operator.