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] +“你想要吗?”);并再次阅读价值,我该怎么做?
答案 0 :(得分:0)
while (cont.equalsIgnoreCase("N")){
//Do stuff
}
答案 1 :(得分:0)
你可以去做一个do-while循环,即
do
{
..........
.........
}while(cont.equalsIgnoreCase("N"));
还有一件事情不需要使用equals()来检查大写和小写字母,而是去找equalsIgnoreCase()