尝试使用以下代码从主类运行 start 方法时:
public class rungame {
public void run() {
Menu.start(string[]);
}
}
我试图运行的方法是:
public class Menu{
public static void start(String[] args){
for( ; ; ){
System.out.println("\nWelcome To The Block Game By Joe Easton\n");
System.out.println("Enter S To Start");
System.out.println("Enter H For Help");
System.out.println("Enter E To Exit");
System.out.println("\nWhat is your command?");
//loop looking for input
for( ; ; ){
//private
String answer;
Keyboard kb = new Keyboard();
answer = kb.readString();
if(answer.charAt(0) == 'S' || answer.charAt(0) == 's' || answer.charAt(0) == 'H' || answer.charAt(0) == 'h' || answer.charAt(0) == 'e' || answer.charAt(0) == 'E') {
if(answer.charAt(0) == 'S' || answer.charAt(0) == 's'){
System.out.println("\nWhat is your name?");
String name;
name = kb.readString();
System.out.println("\nPress y to start");
String start;
start = kb.readString();
if(answer.charAt(0) == 'y' || answer.charAt(0) == 'Y') {
}
else{break;
}
}
if(answer.charAt(0) == 'H' || answer.charAt(0) == 'h'){
System.out.println("\nIn this game, you have to avoid the B's by moving your character P. \nThe longer you last, the more points you get. \n\nTo move your character:\nUse the G key to go left\nUse the H key to go right\nUse the J key to go up\nUse the K key to go down");
System.out.println("\nWhat is your command?");
}
if(answer.charAt(0) == 'E' || answer.charAt(0) == 'e'){
System.exit(0);
}
}
else{System.out.println("\nInvalid Command!");
System.out.println("\nWhat is your command?");
}
}
}
}
}
当我尝试从另一个类运行它时出现 .class 预期错误,菜单类编译并运行良好