【发布时间】:2018-11-15 15:36:56
【问题描述】:
那里会有多少客人? 4
输入客人 1 的选择
输入客人 2 的选择
在我输入客人数量后,客人 1 和 2 正好落在彼此之下,我没有机会输入客人 1 的选择,它转到客人 2。 我该如何解决这个问题?
public static void main(String[] args) {
Scanner simpleInput= new Scanner (System.in);
int guest;
String choice;
System.out.println("Welcome to Tying the Knot Wedding Planner Guide");
System.out.println();
System.out.println("For each guest, please enter he/her choice for dinner: Beef, Chicken, Fish, or\r\n" +
"Vegetarian.\r\n" +
"");
System.out.print("How many guests will there be there? ");
guest=simpleInput.nextInt();
while (guest <0 )
{
System.out.println ( "That was not a valid number, try again. " );
System.out.println("How many guests will there be there? ");
guest=simpleInput.nextInt();
}
for (int x = 1; x < guest; x++ )
{
System.out.println("Enter the choice for guest " + x);
choice=simpleInput.nextLine();
}
System.out.println("There will be " + guest + " meals");
}
【问题讨论】:
-
谢谢。它帮助很大。