0

I am trying to learn Java and was specifically learning about User Input using Scanner class.

I was wondering if you can add something like a ':' or ';' after a prompt.

My understanding is somewhat like this

Scanner var1 = new Scanner(System.in); //Creates a new object of scanner class
String var2 = var1.next(); //Stores input in a string variable

So what should be the way to put a ":" after the prompt, in the same line?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

4

You can create a prompt on the same line as the user input by using System.out.print(prompt)

Note that this is not the same as System.out.println(prompt), which puts a newline after the string to be printed.

Example:

System.out.print("Enter your value: ");
String value = myScanner.next();
kuhnertdm
  • 144
  • 5