1
            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("\nHow many " + arr[c][0] + " 你想要吗?"); 并再次读取值,我该怎么做?

4

2 回答 2

0

你可以去一个do-while循环,即

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

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

于 2013-04-13T13:22:54.457 回答
0
while (cont.equalsIgnoreCase("N")){
//Do stuff
}
于 2013-04-13T13:06:09.187 回答