Issue
recently I installed netbeans 12.0, I noticed that when running a project, it always executes the scanner before the output of print. Such as.
System.out.print("Name : ");
String name = scanner.nextLine();
and returning an output like this if I entered John while executing:
John
Name:
desired output
Name: John
Solution
I believe your problem lies in your print statement:
System.out.println("Name: ");
What should have happened was this:
String name = scanner.nextLine();
System.out.println("Name: " + name);
So what I did was I'm assigning the "name" variable first, and then I'm concatenating 2 strings together ("concatenating" basically means putting 2 strings together).
Answered By - David Lee
Answer Checked By - Willingham (JavaFixing Volunteer)