当控制台给出 3 个相同的项目时,检查在代码中不起作用
public class casino {
public static String getIngot(){
String[] ingots = new String[]{"iron","gold","diamond"};
int n = (int)Math.floor(Math.random() * ingots.length);
if(ingots[n] == "iron"){
return "[I]";
}
else if(ingots[n] == "gold"){
return "[G]";
}
else if(ingots[n] == "diamond"){
return "[D]";
}
return null;
}
public static void main(String[] args) {
String slots = (getIngot()+getIngot()+getIngot());
System.out.println(slots);
if (slots == "[I][I][I]"){
System.out.println("IRON");
}
if (slots == "[G][G][G]"){
System.out.println("GOLD");
}
if (slots == "[D][D][D]"){
System.out.println("DIAMOND");
}
}
}
1 个回答