Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么不';当我运行代码(在Eclipse中)时,我没有得到任何输出吗?_Java - Fatal编程技术网

Java 为什么不';当我运行代码(在Eclipse中)时,我没有得到任何输出吗?

Java 为什么不';当我运行代码(在Eclipse中)时,我没有得到任何输出吗?,java,Java,Eclipse并没有显示我做错了什么,但当我点击run时,它的控制台就会闪烁并保持空白 有人能指出我做错了什么吗 我对大部分代码都进行了注释,但如果您在尝试了解我在做什么时遇到问题,请执行以下操作: 电脑玩家和用户掷骰子。两个骰子卷都是从1到6的随机数 有10发子弹。谁赢了一轮就得一分 最后,所有分数相加,并宣布获胜 (number=1;number>=numRolls;number++)的for循环中的条件number>=numRolls始终为false 将其更改为numberfor(nu

Eclipse并没有显示我做错了什么,但当我点击run时,它的控制台就会闪烁并保持空白

有人能指出我做错了什么吗

我对大部分代码都进行了注释,但如果您在尝试了解我在做什么时遇到问题,请执行以下操作:

  • 电脑玩家和用户掷骰子。两个骰子卷都是从1到6的随机数
  • 有10发子弹。谁赢了一轮就得一分
  • 最后,所有分数相加,并宣布获胜

(number=1;number>=numRolls;number++)的for循环中的条件
number>=numRolls
始终为false


将其更改为
numberfor(number=1;number>=numRolls;number++)的for循环
中的条件
number>=numRolls
始终为false


将其更改为
number Wow。谢谢。无需发表感谢评论;相反,接受这个答案。通过这种方式,其他用户知道这个问题已经有了一个公认的答案,所以不要试图回答它(除非他们认为他们有更好的答案)。哇。谢谢。无需发表感谢评论;相反,接受这个答案。通过这种方式,其他用户知道这个问题已经有了一个公认的答案,所以不要试图回答它(除非他们认为自己有更好的答案)。确保正确标记您的问题。这是Java代码,应该这样标记,而不是javascript。(我已经做了相应的编辑)。我还把你的问题标记为一个排版,因为它看起来像是一个打印错误,而不是一个实际问题,其他用户会感兴趣或认为是有帮助的;如果你同意我的观点,你也可以选择删除你的问题,因为这只是一个打字错误。没什么需要注意的。确保正确标记您的问题。这是Java代码,应该这样标记,而不是javascript。(我已经做了相应的编辑)。我还把你的问题标记为一个排版,因为它看起来像是一个打印错误,而不是一个实际问题,其他用户会感兴趣或认为是有帮助的;你也可以选择删除你的问题,如果你同意我的意见,那只是一个打字错误。
import java.util.Random; // Imports RNG

public class Guarascio_Chap_4_21 {

    // Calls for main
    public static void main(String[] args) {

        // Create Random Object to create random numbers
        Random randomNumbers = new Random();

        // List of variables
        int number;
        int compPlayer;
        int userPlayer;
        int compScore = 0;
        int userScore = 0;
        int numRolls = 10;

        // For loop that begins at 1 and counts by 1 until it completes numRolls
        for (number = 1; number >= numRolls; number++)
        {

            // CompPlayer rolls the dice, then prints the number
            compPlayer = randomNumbers.nextInt(7)+1;
            System.out.println("Computer rolls a "+ compPlayer);

            // UserPlayer rolls the dice, then prints the number
            userPlayer = randomNumbers.nextInt(7)+1;
            System.out.println("User rolls a "+ userPlayer);

            // If/Else loop that informs the user which player has won the roll, 1 point is added to winners score 
            if (compPlayer > userPlayer)
            {
                compScore = (compScore + 1);
                System.out.println("Computer gains 1 point");
            }


            else
            {
                userScore = (userScore + 1);
                System.out.println("User gains 1 point");
            }

            // Print out both users and comps score
            System.out.println("Computers score is " + compScore);
            System.out.println("Users score is " + userScore);


            // Compare scores to decide winner
            if (compScore > userScore)
            {
                System.out.println("Computer wins with " + compScore + " points!");
            }

            else
            {
                System.out.println("User wins with " + userScore + " points!");
            }

        }

    }

}