Java 如果我没有';你不告诉它吗?

Java 如果我没有';你不告诉它吗?,java,Java,这是一个简单的垃圾游戏,我不明白为什么代码在最后两次提示用户一个问题。如果我说(y)下注,它只会提示用户两次问题。 输出 你想玩骰子吗?(是/否) Y 你现在的现金罐是100美元 Would you like to bet? (y/n) n Press "ENTER" to continue... Rolling... Dice 1: 1 Dice 2: 1

这是一个简单的垃圾游戏,我不明白为什么代码在最后两次提示用户一个问题。如果我说(y)下注,它只会提示用户两次问题。 输出 你想玩骰子吗?(是/否) Y 你现在的现金罐是100美元

            Would you like to bet? (y/n) n
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 1
            Dice 2: 1
            Total: 2
            You Lost... :(
            Your total now is $100

            Do you want to play craps? (y/n) 
            y
            Your current cash pot is: $100

            Would you like to bet? (y/n) n
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 2
            Dice 2: 6
            Total: 8
            {Your POINT is: 8}

            Rolling for the Point: 8
            Press "ENTER" to continue...

            Dice 1: 3
            Dice 2: 2
            {Total: 5}
            Rolling for the Point: 8
            Press "ENTER" to continue...

            Dice 1: 1
            Dice 2: 5
            {Total: 6}
            Rolling for the Point: 8
            Press "ENTER" to continue...

            Dice 1: 6
            Dice 2: 1
            {Total: 7}
            You Lost...
            Your total now is $100

            Do you want to play craps? (y/n) 
            y
            Your current cash pot is: $100

            Would you like to bet? (y/n) y
            How much would you like to bet? $5
            Your bet stands at $5
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 2
            Dice 2: 6
            Total: 8
            {Your POINT is: 8}

            Rolling for the Point: 8
            Press "ENTER" to continue...

            Dice 1: 5
            Dice 2: 4
            {Total: 9}
            Rolling for the Point: 8
            Press "ENTER" to continue...

            Dice 1: 5
            Dice 2: 3
            {Total: 8}
            You Won!!!
            Your total now is $105

            Do you want to play craps? (y/n) 

            Do you want to play craps? (y/n) 
            y
            Your current cash pot is: $105

            Would you like to bet? (y/n) y
            How much would you like to bet? $5
            Your bet stands at $5
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 5
            Dice 2: 6
            Total: 11
            You Won!! :)
            Your total now is $110

            Do you want to play craps? (y/n) 

            Do you want to play craps? (y/n) 
            y
            Your current cash pot is: $110

            Would you like to bet? (y/n) y
            How much would you like to bet? $5
            Your bet stands at $5
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 4
            Dice 2: 5
            Total: 9
            {Your POINT is: 9}

            Rolling for the Point: 9
            Press "ENTER" to continue...

            Dice 1: 6
            Dice 2: 3
            {Total: 9}
            You Won!!!
            Your total now is $115

            Do you want to play craps? (y/n) 

            Do you want to play craps? (y/n) 
            y
            Your current cash pot is: $115

            Would you like to bet? (y/n) n
            Press "ENTER" to continue...

            Rolling...
            Dice 1: 5
            Dice 2: 5
            Total: 10
            {Your POINT is: 10}

            Rolling for the Point: 10
            Press "ENTER" to continue...

            Dice 1: 5
            Dice 2: 3
            {Total: 8}
            Rolling for the Point: 10
            Press "ENTER" to continue...

            Dice 1: 1
            Dice 2: 1
            {Total: 2}
            Rolling for the Point: 10
            Press "ENTER" to continue...

            Dice 1: 4
            Dice 2: 2
            {Total: 6}
            Rolling for the Point: 10
            Press "ENTER" to continue...

            Dice 1: 5
            Dice 2: 1
            {Total: 6}
            Rolling for the Point: 10
            Press "ENTER" to continue...

            Dice 1: 2
            Dice 2: 5
            {Total: 7}
            You Lost...
            Your total now is $115

            Do you want to play craps? (y/n) 
            n
            Good bye.
            ----Statistics----
            Won:  3
            Lost: 4
            Cash: $115
下面是我正在运行的源代码: 一揽子计划3

            import java.util.Random;    // Used for generating a random number dice
            import java.util.Scanner;   // Used for getting input from user

            /**
             *
             * @author Sartaj Singh
             */
            public class Project3 {

                /**
                 *
                 */
                public static void promptEnterKey() {
                    System.out.println("Press \"ENTER\" to continue...");
                    Scanner scanner = new Scanner(System.in);
                    scanner.nextLine();
                }

                public static void main(String[] args) {
                    int pot = 100;
                    int bet = 0;
                    int wins = 0;
                    int losses = 0;
                    //  int games = 0;

                    // Make an instance of the Random and Scanner Class
                    Random random = new Random();
                    Scanner input = new Scanner(System.in);
                    while (pot >= 1) {
                        System.out.println();
                        System.out.println("Do you want to play craps? (y/n) ");
                        String play_choice = input.nextLine();
                        if ("N".equals(play_choice) || "n".equals(play_choice)) {
                            System.out.println("Good bye.");
                            System.out.println("----Statistics----");
                            System.out.println("Won:  " + wins);
                            System.out.println("Lost: " + losses);
                            System.out.println("Cash: $" + pot);
                            break;
                        }

                        else if ("Y".equals(play_choice) || "y".equals(play_choice)) {
                            System.out.println("Your current cash pot is: $" + pot);
                            System.out.println();
                            System.out.print("Would you like to bet? (y/n) ");
                            String bet_choice = input.nextLine();
                            if ("y".equals(bet_choice) || "Y".equals(bet_choice)) {
                                System.out.print("How much would you like to bet? $");
                                bet = input.nextInt();
                                while (bet < 1 || bet > pot) {
                                    System.out.print("YOU CANT BET THAT AMOUNT! How much would you like to bet? $");
                                    bet = input.nextInt();
                                }
                                System.out.println("Your bet stands at $" + bet);

                            }
                            if ("n".equals(bet_choice) || "N".equals(bet_choice)) {
                                bet = 0;
                            }
                            promptEnterKey();
                            System.out.println("Rolling...");
                            int dice1;
                            dice1 = random.nextInt(6) + 1;
                            int dice2;
                            dice2 = random.nextInt(6) + 1;
                            int dice_total = dice1 + dice2;
                            System.out.println("Dice 1: " + dice1);
                            System.out.println("Dice 2: " + dice2);
                            System.out.println("Total: " + dice_total);
                            switch (dice_total) {
                                case 7:
                                case 11:
                                    System.out.println("You Won!! :)");
                                    pot += bet;
                                    wins++;
                                    System.out.println("Your total now is $" + pot);
                                    break;
                                case 2:
                                case 3:
                                case 12:
                                    System.out.println("You Lost... :(");
                                    pot -= bet;
                                    losses++;
                                    System.out.println("Your total now is $" + pot);
                                    break;
                                default:
                                    int point = dice_total;
                                    System.out.println("{Your POINT is: " + point + "}");
                                    System.out.println("");
                                    while (dice_total != 7) {
                                        System.out.println("Rolling for the Point: " + point);
                                        promptEnterKey();
                                        dice1 = random.nextInt(6) + 1;
                                        dice2 = random.nextInt(6) + 1;
                                        dice_total = dice1 + dice2;
                                        System.out.println("Dice 1: " + dice1);
                                        System.out.println("Dice 2: " + dice2);
                                        System.out.println("{Total: " + dice_total + "}");
                                        if (dice_total == point) {
                                            System.out.println("You Won!!!");
                                            pot += bet;
                                            wins++;
                                            System.out.println("Your total now is $" + pot);
                                            break;
                                        } else if (dice_total == 7) {
                                            System.out.println("You Lost...");
                                            pot -= bet;
                                            losses++;
                                            System.out.println("Your total now is $" + pot);
                                            break;
                                        }
                                    }
                            }
                        }
                    }
                }
            }
import java.util.Random;//用于生成随机数骰子
导入java.util.Scanner;//用于从用户获取输入
/**
*
*@作者Sartaj Singh
*/
公共类项目3{
/**
*
*/
公共静态void prompterkey(){
System.out.println(“按“回车”继续…”);
扫描仪=新的扫描仪(System.in);
scanner.nextLine();
}
公共静态void main(字符串[]args){
int pot=100;
int-bet=0;
int=0;
整数损失=0;
//整数游戏=0;
//创建Random和Scanner类的实例
随机=新随机();
扫描仪输入=新扫描仪(System.in);
while(pot>=1){
System.out.println();
System.out.println(“你想玩骰子吗?(y/n)”);
String play_choice=input.nextLine();
如果(“N.equals(play_-choice)| |“N.equals(play_-choice)){
System.out.println(“再见”);
System.out.println(“----统计----”;
System.out.println(“赢得:+wins”);
系统输出打印项次(“丢失:+丢失);
System.out.println(“现金:$”+pot);
打破
}
否则如果(“Y”。等于(玩你的选择)| |“Y”。等于(玩你的选择)){
System.out.println(“您当前的现金罐为:$”+罐);
System.out.println();
系统输出打印(“您想下注吗?(y/n)”);
字符串bet_choice=input.nextLine();
如果(“y”。等于(下注选择)| |“y”。等于(下注选择)){
System.out.print(“您想赌多少?$”;
bet=input.nextInt();
而(下注<1 | |下注>pot){
System.out.print(“你不能下注那个金额!你想下注多少?$”;
bet=input.nextInt();
}
System.out.println(“您的赌注为$”+赌注);
}
如果(“n.equals(bet_-choice)| |“n.equals(bet_-choice)){
bet=0;
}
prompterkey();
System.out.println(“滚动…”);
int-1;
dice1=随机。nextInt(6)+1;
int-2;
dice2=随机。下一个(6)+1;
int dice_total=dice1+dice2;
System.out.println(“骰子1:+dice1”);
System.out.println(“骰子2:+dice2”);
System.out.println(“总计:+dice_总计”);
开关(骰子总数){
案例7:
案例11:
System.out.println(“你赢了!!:)”;
赌注+=赌注;
wins++;
System.out.println(“您现在的总数为$”+罐);
打破
案例2:
案例3:
案例12:
System.out.println(“您丢失了…:(”);
赌注-=赌注;
损失++;
System.out.println(“您现在的总数为$”+罐);
打破
违约:
积分=骰子总数;
println({您的点是:“+POINT+”});
System.out.println(“”);
而(骰子总数!=7){
System.out.println(“点滚动:+点);
prompterkey();
dice1=随机。nextInt(6)+1;
dice2=随机。下一个(6)+1;
骰子总数=骰子1+骰子2;
System.out.println(“骰子1:+dice1”);
System.out.println(“骰子2:+dice2”);
System.out.println(“{Total:+dice_Total+”}”);
如果(骰子总数==点数){
System.out.println(“你赢了!!!”;
赌注+=赌注;
wins++;
System.out.println(“您现在的总数为$”+罐);
if ("y".equals(bet_choice) || "Y".equals(bet_choice)) {
    System.out.print("How much would you like to bet? $");
    bet = input.nextInt();
    while (bet < 1 || bet > pot) {
        System.out.print("YOU CANT BET THAT AMOUNT! How much would you like to bet? $");
        bet = input.nextInt();
    }
    /* Add Here */
    input.nextLine();
    System.out.println("Your bet stands at $" + bet);
}