你好, 我现在正在尝试免费编写一种游戏。 我前段时间在学校开始编码,但最近我们没有用 Java 做太多事情,所以我想我应该做点什么,这样我就不会忘记一切。嗯,我仍然需要一些,因为我们从来没有做过这样的事情。我的问题是它显示一个错误并告诉我缺少一个符号。该程序应该启动游戏,然后与不同类型的对象进行交互,这些对象包含角色信息,例如怪物和玩家的统计数据。
import java.util.Scanner;
public class Spiel{
public static void main(String[] args) {
System.out.print("What is your name Adventurer?\n ");
Scanner scanner = new Scanner(System. in);
String Abenteurername = scanner. nextLine();
System.out.println("Adventurer "+Abenteurername+" will you help us clean the dungeon? \n");
String Spielstart = scanner. nextLine();
if (Spielstart.equalsIgnoreCase(ja)) {
System.out.println("Gut");
} else {
System.exit(0);
} // end of if-else
}
}
答案 0 :(得分:0)
当你写的 ja
没有引号时,它希望找到一个用那个名字定义的变量,比如
String ja = "ja";
if (Spielstart.equalsIgnoreCase(ja)) {
System.out.println("Gut");
}
但你想要的只是
if (Spielstart.equalsIgnoreCase("ja")) {
System.out.println("Gut");
} else {
System.exit(0);
} // end of if-else