I’m trying to read 6 lines of user input, but I can’t get them to print correctly.
I first did this:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name, name2;
double price, price2;
int item, item2;
System.out.print("Name: ");
name = input.next();
System.out.print("Price: ");
price = input.nextDouble();
System.out.print("Item Number: ");
item = input.nextInt();
System.out.println("");
System.out.print("Name 2: ");
name = input.next();
System.out.print("Price 2: ");
price = input.nextDouble();
System.out.print("Item Number 2: ");
item = input.nextInt();
System.out.println("");
}
}
And after I test it won't let me input past "Price:" (I'm on BlueJ btw).
Name: Jack B
Price:
I tried with input.nextLine();
instead of input.next()
, but ended up with this
Name: Jack B
Price: 30
Item Number: 10
Name 2: Price 2:
It works if the String doesn’t have spaces, but if it has one, this will happen. How do I get it to print the 6 lines normally?