【发布时间】:2020-08-24 14:53:41
【问题描述】:
好的,所以我做了一个逃离房间的程序,但布尔值不起作用
class Main {
public static void main(String[] args) {
System.out.println("Welcome To The Hogwarts Escape Room");
System.out.println("To Play The Hogwarts Escape Room Press Y");
Scanner sc = new Scanner(System.in);
String useranswer = sc.nextLine();
boolean light = false;
// This is not my entire code but the part that was necessary.
System.out.println("Press U to look up");
useranswer = sc.nextLine();
if (usernaswer.equals("U"){
System.out.println(" You look above you and see nothing as the ceiling is too dark to see in.");
System.out.println("Would you like to: \n Look Closer press A \n Return To Your Original Position press B");
useranswer = sc.nextLine();
System.out.println(light);
// this part doesn't work.. I checked and made sure the useranswer was A and the boolean does equal to false.
if (useranswer.equals("A")&&(light = false)){
ceilingCloserlightFalse(sc, useranswer, inventory, light);
}
else if (useranswer.equals("B")){
original(sc, useranswer, inventory, light);
}
// this was the setup to the constructor
public static void ceilingCloserlightFalse(Scanner sc, String useranswer, String [] inventory, boolean light){
System.out.println("You go closer and see something faintly but cant tell what it is without a light");
System.out.println("You returned to the original position because there was nothing else to do there.");
original(sc, useranswer, inventory, light);
}
}
}
好的,所以我想知道我的方法或 && 运算符是否有问题。我检查以确保 useranswer 是 a 并且我还检查以确保
【问题讨论】:
-
light = false你的意思可能是==。此外,usernaswer看起来像是一个错字。很难说它为什么不起作用,因为你没有说它应该做什么,也没有说它做什么。