I get “Type mismatch cannot convert from int to boolean” despite not using boolean

Your code

if (coinValue = 1) {System.out.println("HEADS!"); heads++;}
if (coinValue = 2) {System.out.println("TAILS!"); tails++;}

Should be

if (coinValue == 1) {System.out.println("HEADS!"); heads++;}
if (coinValue == 2) {System.out.println("TAILS!"); tails++;}

You’re assigning an int type to coinValue and that is being evaluated as a bool inside the if statement.

Leave a Comment