gpt4 book ai didi

java - 返回再次询问行数

转载 作者:行者123 更新时间:2023-12-01 04:45:06 25 4
gpt4 key购买 nike

            if (choice.equals("1")){
int c = 0;
System.out.println("Welcome " + name + ",");
System.out.println("\nYou have chosen to play [1] " + arr[c][0] +".\n");
System.out.println(arr[c][0] +" costs €" + arr[c][2] + " to play and has a minimum purchase of " + arr[c][1] + " lines.") ;
System.out.print("\nHow many " + arr[c][0] + " would you like? ");
int num = s1.nextInt();

while (num < Integer.parseInt(arr[c][1])){
System.out.println( arr[c][0] + " has a minimum purchase of " + arr[c][1] + " lines");
num = s1.nextInt();
}

System.out.println("\nThe total cost to play "+ arr[c][0] + " will be €" + (num*Double.parseDouble(arr[c][2])));

System.out.println("\nContinue? Y/N/Q");
String cont = s1.next().toUpperCase();
if (cont.equals("N")||cont.equals("n")){
System.out.print("\nHow many " + arr[c][0] + " would you like? ");
}
else if (cont.equals("Q")||cont.equals("q")){
menu();
}
else if (cont.equals("Y")||cont.equals("y")) {
//call the random generator
random(c,num);
//call the menu
menu();
}
else {
System.out.println("Invalid option");
menu();

}

}

如果我选择“N”,它应该再次询问 System.out.print("\n你想要多少个 "+ arr[c][0] + "? ");并再次读取该值,我该怎么做?

最佳答案

你可以使用 do-while 循环,即

do
{
..........
.........
}while(cont.equalsIgnoreCase("N"));

还有一件事不需要使用 equals() 检查大小写字母,而是使用 equalsIgnoreCase()

关于java - 返回再次询问行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15988055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com