就目前而言,控制台允许我编译,但不能运行它,它说:
“错误:无法找到或加载主类 MonsterFight”
这是代码:
class Fight {
Random rand= new Random();
int Hit (int x) {
int numHit = rand.nextInt(100);
return (int) x - numHit;
}
class MonsterFight {
public void main(String [] args){
String name;
int hp = 1000;
System.out.println("You start at 1000 Hitpoints.");
Fight battle = new Fight();
while (hp != 0) {
hp = Hit(hp);
System.out.println("You have now " + hp + " hitpoints.");
}
}
}
}
我似乎无法让它工作。感谢所有帮助,也感谢使这个更清洁的提示,因为我对 Java 还很陌生。