我的代码可能看起来很糟糕,但那是因为我必须审查粗言秽语。
当有人输入“蝙蝠”,“蝙蝠”或“BATS”时,我试图让它终止。
import java.util.*;
public class BATS
{
public static void main(String[] args)
{
Scanner BAT = new Scanner(System.in);
String Bat, BATS;
System.out.println("What is the most badass flying mammal ever?!");
Bat = BAT.nextLine();
Bat = Bat.toUpperCase();
while(Bat != "BATS")
{
System.out.println("No, its BATS!!!!!!!!!! Try again.");
Bat = BAT.nextLine();
Bat = Bat.toUpperCase();
if(Bat == "BATS")
{
System.out.println("YOU'RE RIGHT THEY ARE !!!!!");
break;
}
}
}
}
答案 0 :(得分:0)
while(Bat != "BATS")
错误地
您需要比较内容而不是引用...
改为:
while(!"BATS".equalsIgnoreCase(Bat))