This is my program at the moment:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String actionNum;
while(true) {
//User validation
while(true) {
System.out.print("Type 1: ");
actionNum = input.nextLine();
if(actionNum.equals("1")) {
break;
}
}
if(actionNum.equals("1")) {
System.out.print("Enter word: ");
String meals = input.nextLine();
System.out.print("Enter number: ");
int cost = input.nextInt();
}
}
}
}
When I use nextInt();
on line 22 in my program, the console prints out:
Enter word: word
Enter number: 1
Type 1: Type 1:
Why is Type 1:
being printed out twice? If I take out the nextInt();
, only one Type 1:
is printed out, which is what I want. Is something in my program causing it to do enter twice?