I’ve just started learning Java and have come across a little quirk I’m not sure how to solve. It’s the same as this question but the solution there doesn’t work here. The problem there was thought to be the result of something to do with Netbeans, and compiling the code form the command line may solve the problem, but I am compiling and running from the command line.
Basically, when I run the following code (snipped for brevity)
System.out.println("Number: ");
line = in.readLine();
I get the following output:
Number:
//Input cursor is found here
I’m running the code using the Gnome Terminal that ships with Ubuntu. Does anyone know what’s causing this?
Use
printinstead ofprintlnif you don’t want the trailing line break:The Javadocs for
printlnalready say so: