好的,因此下面的代码可以完美地循环。它可以根据需要循环播放。事实是,我永远也无法摆脱困境。顺便说一句,对于那些想知道的人,我正在尝试构建一个文字冒险游戏,但我确实需要摆脱这种循环。
System.out.println("\n\nWelcome, " + name + "! To proceed, enter your class of fighter.");
System.out.println();
boolean x = true;
while (x){
//information print statements
System.out.println("What will your class be? ");
String heroclass = scan.nextLine();
heroclass.toLowerCase();
String A;
switch (heroclass)
{
case "slayer": A = "You have selected the Slayer class.";
break;
case "blader": A = "You have selected the Blader class.";
break;
case "bandit": A = "You have selected the Bandit class.";
break;
case "wizard": A = "You have selected the Wizard class.";
break;
default: A = "Invalid entry.";
break;
}
String killloop = A;
if (killloop.charAt(0) == 'Y'){
x = false;
}
}
最佳答案
您需要将heroclass.toLowerCase();
分配给heroclass
的原始值:
heroclass = heroclass.toLowerCase();
如果不这样做,将不会保存小写的heroclass版本。