-4
我无法在Eclipse中运行此程序。 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;
}
}
}
}
那么当您尝试会怎么样? CoinFace是什么?你的'main'方法在哪里?你没有给我们足够的信息。请阅读http://tinyurl.com/so-list –
我看不到这里的主要方法 –
我真的很希望你在那里有'main' .. – Maroun