lundi 25 juin 2018

Booleans, if-else statements, and scanner?

I am trying to make the "yes" (or "y" in this case) response to a question a true statement. Any other response to the question below is known to be a false statement.

System.out.print("Do you smoke?(y/n): ");
        boolean smoker = console.nextBoolean();
        if (smoker.equalsIgnoreCase("y")) {
            smoker = true;
        } else {
            smoker = false;
        }

I get the error

HealthPlan.java:32: error: boolean cannot be dereferenced
        if (smoker.equalsIgnoreCase("y")) {
              ^

Does anyone know how I can fix this? I have searched this online and I am not so sure.

Aucun commentaire:

Enregistrer un commentaire