我想循環用戶輸入的味道和勺的數量,直到當問'購買更多的冰淇淋?用戶輸入'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
解析發佈代碼:嗶聲:錯誤:部分代碼丟失 –