我想循环用户输入的味道和勺的数量,直到当问'购买更多的冰淇淋?用户输入'n',但输入'n'时显示报告,然后再次询问味道?我怎样才能阻止呢?如何修复连续循环?
Scanner in = new Scanner(System.in);
int index = 0;
{
System.out.println("What flavour was chosen (strawberry, vanilla, chocolate) or type 'end' to finish?");
iceCreamCone[0] = in.nextLine();
System.out.println("How many scoops of this flavour?");
iceCreamCone[0] = in.nextLine();
index = index + 1;
char choice;
System.out.println("More ice cream purchased (y/n):");
{
choice = in.next().charAt(0);
while (choice == 'y')
{
System.out.println("What flavour was chosen (strawberry, vanilla, chocolate) or type 'end' to finish?");
iceCreamCone[1] = in.nextLine();
in.nextLine();
System.out.println("How many scoops of this flavour?");
iceCreamCone[1] = in.nextLine();
index = index + 1;
}
if (choice == 'n') {
{
System.out.println("Report for today: \nTotal ice cream cones sold: \nTotal sales from the customers: ");
}
}
}
}
}
你可以使用“休息”摆脱循环..但你的循环在哪里? – TheLostMind
使用一个简单的'while(expression == true)'循环。 – Tdorno
解析发布代码:哔声:错误:部分代码丢失 –