Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.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中运行此程序。Eclipse没有说有什么问题,我就是打不开。每次我尝试时,它都会在我的默认包中打开另一个程序 import acm.util.*; /** * This class decides the face of a coin. * 1 and 2 represent correspondingly Heads and Tails. * Clients can get the "face" of the coin by calling getState()

我无法在Eclipse中运行此程序。Eclipse没有说有什么问题,我就是打不开。每次我尝试时,它都会在我的默认包中打开另一个程序

import acm.util.*;

/**
 * This class decides the face of a coin. 
 * 1 and 2 represent correspondingly Heads and Tails.
 * Clients can get the "face" of the coin by calling getState() method.
 */

public class CoinFace {

    public CoinFace() {
        state = rgen.nextInt(1, 2);
    }

    private int state;

    public int getState() {
        return state;
    }

    private RandomGenerator rgen = new RandomGenerator();
}

public class ConsecutiveHeads extends CoinFace{
    public void run () {
        while (true) {
            int totalFlip = 0;
            int consecutiveHeads = 0;
            CoinFace a = new CoinFace();
            if (a.getState() == 1) {
                System.out.print("Heads");
                totalFlip++;
                consecutiveHeads++;
            } else if (consecutiveHeads == 3) {
                System.out.print("It took " + totalFlip + " to get 3 consecutive heads." );
                break;
            } else {
                System.out.print("Tails");
                consecutiveHeads = 0;
            }
        }
    }
}

您忘记声明主方法:

public static void main(String args[]) {
  new ConsecutiveHeads().run(); 
}

那么当你尝试时会发生什么呢?什么是铸币面?你的主要方法是什么?你没有给我们足够的信息。请阅读我在这里看不到主要方法我真的希望你在那里有主要方法@ᴍ阿伦ᴍ阿隆,他也希望:D-1指责日食。