Java 获取最后一个}上的错误还有其他原因

Java 获取最后一个}上的错误还有其他原因,java,Java,收到一个错误,说我需要另一个while语句,我已经检查了}多次,但idk出了什么问题 如果用户输入“y”,我如何重新运行程序 谢谢 import java.util.Scanner; 公共级查尔斯胡椒计划6{ 公共静态void main(字符串[]args) { 扫描仪用户=新扫描仪(System.in); //显示欢迎/说明 System.out.println(); System.out.println(); System.out.println(“欢迎使用计算机骰子”); System.o

收到一个错误,说我需要另一个while语句,我已经检查了}多次,但idk出了什么问题
如果用户输入“y”,我如何重新运行程序
谢谢

import java.util.Scanner;
公共级查尔斯胡椒计划6{
公共静态void main(字符串[]args)
{
扫描仪用户=新扫描仪(System.in);
//显示欢迎/说明
System.out.println();
System.out.println();
System.out.println(“欢迎使用计算机骰子”);
System.out.println(“-------------------------------------------------------------”;
System.out.println(“您将与计算机玩骰子”);
System.out.println();
System.out.println(“你只能用一对或一对赢得比赛”);
System.out.println(“任何一对都胜过任何一条直线”);
System.out.println(“任何一对都胜过任何一个垃圾”);
System.out.println(“任何直人都能打败任何垃圾”);
System.out.println(“如果是两对-高对赢”);
System.out.println(“在两个直道的情况下-高直道获胜”);
System.out.println(“如果打成平局,你输了”);
System.out.println(“-------------------------------------------------------------”;
System.out.println();
System.out.println();
//两个人死了
int d1;
int d2;
int d3;
int d4;
//跟踪结果
int=0;
int=0;
int=0;
//再次播放响应
串pa;
做
{
//掷两个骰子
d1=(int)(Math.random()*6)+1;
d2=(int)(Math.random()*6)+1;
d3=(int)(Math.random()*6)+1;
d4=(int)(Math.random()*6)+1;
//显示掷骰子的结果
System.out.println(“播放器”);
系统输出打印项次(“----------”);
系统输出打印(“+d1+”+d2);
系统输出打印(“\n\n”);
系统输出打印(“计算机”);
系统输出打印项次(“----------”);
系统输出打印(“+d3+”+d4);
系统输出打印(“\n\n”);
//确定这是赢还是输
如果(d1==d2)//对
{
if(d3==d4)//计算机对
{
if(d1>d3)//更高的一对
{
++胜利;
System.out.println(“恭喜,你赢了!”);
}
if(d1(d3+d4))
{
++胜利;
System.out.println(“恭喜,你赢了!”);
}
如果((d1+d2)<(d3+d4))
{
++失去;
System.out.println(“对不起,你输了!”);
}
如果((d1+d2)=(d3+d4))
{
++失去;
System.out.println(“对不起,你输了!”);
}
}
如果(d3==d4)
{
++失去;
System.out.println(“对不起,你输了!”);
}
其他的
{
++胜利;
System.out.println(“恭喜,你赢了!”);
}
}
System.out.println();
//再次播放问题/答案
做
{
System.out.print(“您希望再次播放[y,n]:”;
pa=user.next();
}
而(!(pa.equalsIgnoreCase(“y”)| | pa.equalsIgnoreCase(“n”));
System.out.println(“\n”);
//显示最终结果/报告
System.out.println();
System.out.println(“计算机骰子结果”);
System.out.println(“--------------------------”;
System.out.println(“你玩了”+(赢+平+输)+“回合”);
System.out.println();
System.out.println(“轮数将\t:+wins”);
System.out.println(“轮数丢失\t:+loss”);
System.out.println(“--------------------------”;
System.out.println();
user.close();
}
}

您的第一个
do
语句没有相应的
,而结尾的
语句则是
。另外,您还有一个额外的
您有4个错误,这是工作代码

第一个错误:您最后的
}
号码错误

第二个错误:您没有初始化变量
pa

第三个错误:在
do
周期结束时,您缺少

Foruth错误:您关闭输入太快

import java.util.Scanner;

public class Charles_Peppers_Prog6 {

    public static void main(String[] args) {
        Scanner user = new Scanner(System.in);

        // display the welcome / instructions
        System.out.println();
        System.out.println();
        System.out.println("     Welcome to Computer Dice");
        System.out.println("----------------------------------------------");
        System.out.println("You will be playing dice against the computer");
        System.out.println();
        System.out.println("you can only win with a Pair or a Straight");
        System.out.println("any Pair beats any Straight");
        System.out.println("any Pair beats any Junker");
        System.out.println("any Straight beats any Junker");
        System.out.println("in case of two Pairs - high Pair wins");
        System.out.println("in case of two Straights - high Straight wins");
        System.out.println("in case of a tie, you lose");
        System.out.println("----------------------------------------------");
        System.out.println();
        System.out.println();

        // for the two die
        int d1;
        int d2;
        int d3;
        int d4;

        // keep track of results
        int wins = 0;
        int ties = 0;
        int loses = 0;

        // play again response
        String pa = "";

        do {
            // roll the two die
            d1 = (int) (Math.random() * 6) + 1;
            d2 = (int) (Math.random() * 6) + 1;
            d3 = (int) (Math.random() * 6) + 1;
            d4 = (int) (Math.random() * 6) + 1;

            // display the result of the dice roll
            System.out.println(" Player ");
            System.out.println("--------");
            System.out.print("  " + d1 + "  " + d2);
            System.out.print("\n\n");

            System.out.println(" Computer ");
            System.out.println("--------");
            System.out.print("  " + d3 + "  " + d4);
            System.out.print("\n\n");

            // determine if it is a win or a loss
            if (d1 == d2) //Pair
            {
                if (d3 == d4) //computer pair
                {
                    if (d1 > d3) //higher pair
                    {
                        ++wins;
                        System.out.println("Congrats, you win!");
                    }
                    if (d1 < d3) //lower pair
                    {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    }
                    if (d1 == d3) {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    }
                } else // only user pair
                {
                    ++wins;
                    System.out.println("Congrats, you win!");
                }
            } else {
                if ((d1 == d2 + 1) || (d1 == d2 - 1)) // Straight
                {
                    if ((d3 == d4 + 1) || (d3 == d4 - 1)) //computer straight
                    {
                        if ((d1 + d2) > (d3 + d4)) {
                            ++wins;
                            System.out.println("Congrats, you win!");
                        }
                        if ((d1 + d2) < (d3 + d4)) {
                            ++loses;
                            System.out.println("Sorry, you lose!");
                        }
                        if ((d1 + d2) == (d3 + d4)) {
                            ++loses;
                            System.out.println("Sorry, you lose!");
                        }
                    }
                    if (d3 == d4) {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    } else {
                        ++wins;
                        System.out.println("Congrats, you win!");
                    }
                }
                System.out.println();

                // play again question / answer
                do {
                    System.out.print("Do you wish to play again [y, n] : ");
                    pa = user.next();
                } while (!(pa.equalsIgnoreCase("y") || pa.equalsIgnoreCase("n")));

                System.out.println("\n");

                // display final results / report
                System.out.println();
                System.out.println("Computer Dice Results");
                System.out.println("---------------------");
                System.out.println("You played " + (wins + ties + loses) + " rounds");
                System.out.println();
                System.out.println("Rounds won\t:" + wins);
                System.out.println("Rounds lost\t:" + loses);
                System.out.println("---------------------");
                System.out.println();
            }
        } while (pa.equalsIgnoreCase("y"));
        user.close();
    }
}
import java.util.Scanner;
公共级查尔斯胡椒计划6{
公共静态void main(字符串[]args){
扫描仪用户=新扫描仪(System.in);
//显示欢迎/说明
System.out.println();
System.out.println();
System.out.println(“欢迎使用计算机骰子”);
System.out.println(“-------------------------------------------------------------”;
System.out.println(“您将与计算机玩骰子”);
System.out.println();
System.out.println(“你只能用一对或一个Stra赢
import java.util.Scanner;

public class Charles_Peppers_Prog6 {

    public static void main(String[] args) {
        Scanner user = new Scanner(System.in);

        // display the welcome / instructions
        System.out.println();
        System.out.println();
        System.out.println("     Welcome to Computer Dice");
        System.out.println("----------------------------------------------");
        System.out.println("You will be playing dice against the computer");
        System.out.println();
        System.out.println("you can only win with a Pair or a Straight");
        System.out.println("any Pair beats any Straight");
        System.out.println("any Pair beats any Junker");
        System.out.println("any Straight beats any Junker");
        System.out.println("in case of two Pairs - high Pair wins");
        System.out.println("in case of two Straights - high Straight wins");
        System.out.println("in case of a tie, you lose");
        System.out.println("----------------------------------------------");
        System.out.println();
        System.out.println();

        // for the two die
        int d1;
        int d2;
        int d3;
        int d4;

        // keep track of results
        int wins = 0;
        int ties = 0;
        int loses = 0;

        // play again response
        String pa = "";

        do {
            // roll the two die
            d1 = (int) (Math.random() * 6) + 1;
            d2 = (int) (Math.random() * 6) + 1;
            d3 = (int) (Math.random() * 6) + 1;
            d4 = (int) (Math.random() * 6) + 1;

            // display the result of the dice roll
            System.out.println(" Player ");
            System.out.println("--------");
            System.out.print("  " + d1 + "  " + d2);
            System.out.print("\n\n");

            System.out.println(" Computer ");
            System.out.println("--------");
            System.out.print("  " + d3 + "  " + d4);
            System.out.print("\n\n");

            // determine if it is a win or a loss
            if (d1 == d2) //Pair
            {
                if (d3 == d4) //computer pair
                {
                    if (d1 > d3) //higher pair
                    {
                        ++wins;
                        System.out.println("Congrats, you win!");
                    }
                    if (d1 < d3) //lower pair
                    {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    }
                    if (d1 == d3) {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    }
                } else // only user pair
                {
                    ++wins;
                    System.out.println("Congrats, you win!");
                }
            } else {
                if ((d1 == d2 + 1) || (d1 == d2 - 1)) // Straight
                {
                    if ((d3 == d4 + 1) || (d3 == d4 - 1)) //computer straight
                    {
                        if ((d1 + d2) > (d3 + d4)) {
                            ++wins;
                            System.out.println("Congrats, you win!");
                        }
                        if ((d1 + d2) < (d3 + d4)) {
                            ++loses;
                            System.out.println("Sorry, you lose!");
                        }
                        if ((d1 + d2) == (d3 + d4)) {
                            ++loses;
                            System.out.println("Sorry, you lose!");
                        }
                    }
                    if (d3 == d4) {
                        ++loses;
                        System.out.println("Sorry, you lose!");
                    } else {
                        ++wins;
                        System.out.println("Congrats, you win!");
                    }
                }
                System.out.println();

                // play again question / answer
                do {
                    System.out.print("Do you wish to play again [y, n] : ");
                    pa = user.next();
                } while (!(pa.equalsIgnoreCase("y") || pa.equalsIgnoreCase("n")));

                System.out.println("\n");

                // display final results / report
                System.out.println();
                System.out.println("Computer Dice Results");
                System.out.println("---------------------");
                System.out.println("You played " + (wins + ties + loses) + " rounds");
                System.out.println();
                System.out.println("Rounds won\t:" + wins);
                System.out.println("Rounds lost\t:" + loses);
                System.out.println("---------------------");
                System.out.println();
            }
        } while (pa.equalsIgnoreCase("y"));
        user.close();
    }
}