当我尝试编译它时,我得到了大量的错误,因为我已经"非法启动类型",并且预期的分号,括号等等。我不知道如何阅读&#39 ;在每扇门后面。 ><
import java.lang.Math.*;
import java.util.Random;
public class Paradox {
public static void main(String[] args){
System.out.println("You have got three doors, there is a price inside each of them. Pick a door: A, B, or C");
Door A = new Door();
Door B = new Door();
Door C = new Door();
Random rand = new Random();
int i = rand.nextInt(3);
System.out.println(i);
if(i==0) {
A.goatorcar="Car";
B.goatorcar="Goat";
C.goatorcar="Goat";
}
else if (i==1){
A.goatorcar="Goat";
B.goatorcar="Car";
C.goatorcar="Goat";
}
else {
A.goatorcar="Goat";
B.goatorcar="Goat";
C.goatorcar="Car";
}
}
System.out.println(A.goatorcar);
System.out.println(B.goatorcar);
System.out.println(C.goatorcar);
}
class Door {
String goatorcar;
}
答案 0 :(得分:3)
你有一个额外的大括号}
:
} <<<<
System.out.println(A.goatorcar);
System.out.println(B.goatorcar);
System.out.println(C.goatorcar);
答案 1 :(得分:0)
您的问题在于System.out.println()语句。在Java中,你不能只做“做”事情。像这样的语句(函数调用)必须在函数内部,在这种情况下是你的主函数。