can i ask an input question and get the answer in the same line on java?

Try adding a flush call to your code:

System.out.print("Please enter your name: ");
System.out.flush();
name = sc.nextLine();

This should force the prompt to print out before input is accepted.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top