gpt4 book ai didi

java - 调用方法 ".class expected"

转载 作者:行者123 更新时间:2023-12-01 15:00:18 25 4
gpt4 key购买 nike

当尝试使用以下代码从主类运行启动方法时:

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 预期错误,菜单类编译并运行良好

最佳答案

什么是string[],您应该传递String[]的有效实例

关于java - 调用方法 ".class expected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com