Java 我的";“如果声明”;即使参数为true,也不要运行
好的,我的代码会像没有错误一样编译,但是应该执行的代码不会真正运行。请帮忙Java 我的";“如果声明”;即使参数为true,也不要运行,java,if-statement,Java,If Statement,好的,我的代码会像没有错误一样编译,但是应该执行的代码不会真正运行。请帮忙 public static void newGameCheck() { String newCharacter = scan.next(); if (newCharacter.equals("New game")) { //more code here, but it does not get executed for some reason } 另一个例子是: public
public static void newGameCheck() {
String newCharacter = scan.next();
if (newCharacter.equals("New game")) {
//more code here, but it does not get executed for some reason
}
另一个例子是:
public static void warriorTurn() {
if (warriorAlive==true) {
etut.choosingTarget();
int target= scan.nextInt();
System.out.println("Now type in which ability you want him to use, make sure to use capitals");
warrior_Weapons_and_Abilities();
String ability= scan.next();
if (ability.equals("Anduril, Foe of Terror")) {
int damage= 100+((int) (Math.random()*50));
etut.loseHealth(target, damage);
mana2=mana2-0;
etut.displayHealth(target);
}
else if (ability.equals("Aethereal Blades")) {
int damage= 250+((int) (Math.random()*100));
etut.loseHealth(target, damage);
mana2=mana2-2;
etut.displayHealth(target);
}
else if (ability.equals("Potion")) {
health2=health2+100;
mana=mana-0;
etut.displayHealth(target);
}
这里^,每当我输入能力名称时,代码仍然不会执行将所有
scan.next()
更改为scan.nextLine()
scan.next()
只读取一个单词。扫描仪上的next()方法返回下一个标记。它可能只是返回第一个单词,除非您将分隔符设置为换行符。请在问题中添加相关的语言标记。是否在调试器中单步执行代码?调试程序。