Wednesday, 11 September 2013

Java Basic Scanner - How to put Input on next line

Java Basic Scanner - How to put Input on next line

I have a basic java question about the scanner utility. Let's say i have a
simple program that takes the user input and stores it in a variable. My
question is when i run the program that asks for multiple inputs, the
cursor starts at the beginning of the question and not after it. My code
is:
public class question3 {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
System.out.println("Enter the first number:");
Float a = s.nextFloat();
System.out.println("Enter the second number:");
Float b = s.nextFloat();
System.out.println("Sum = " + (a+b));
System.out.println("Difference = " + (a-b));
System.out.println("Product = " + (a*b));
}
}
When I run this program it will look like Enter First Number then i type
the number, and then |Enter Second Number. "|" meaning where the blinking
cursor is. When I type it'll show up underneath, but it could confuse the
user so I was wondering what the solution could be.

No comments:

Post a Comment