Reputation: 55
System.out.println("Please enter the amount of money you have here: ");
Scanner have = new Scanner(System.in);
System.out.println("Please enter your starting bet here: ");
Scanner rate = new Scanner(System.in);
int moneyHad = Integer.parseInt(have.next());
int moneyRate = Integer.parseInt(rate.next());
System.out.println(moneyHad + ", " + moneyRate);
There is my code, and this is my output.
Please enter the amount of money you have here:
Please enter your starting bet here: 1
1
1, 1
As you can see it prints them both before it asks, thats why there was no input for line 1 of the output.
Please help me quickly!
Upvotes: 1
Views: 279
Reputation: 59
you need just one scanner object and call nexInt()
method to get the followed entry.
Upvotes: 1
Reputation: 119
Try this :
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter the amount of money you have here: ");
int moneyHad = scanner.nextInt();
System.out.print("Please enter your starting bet here: ");
int moneyRate = scanner.nextInt();
System.out.println(moneyHad + ", " + moneyRate);
Upvotes: 2