Exercise 9: Ternary (Java)


#1



It says this is wrong when it's clearly not:


public class Ternary {
    public static void main(String[] args) {
        
        int fuelLevel = 3;

        char canDrive(fuelLevel > 1) ? 'Y' : 'N';
        System.out.println(canDrive);

    }
}


#2

Hi I think that you should save (fuelLevel > 1) ? 'Y' : 'N'; inside the vriable canDrive

 char canDrive = (fuelLevel > 1) ? 'Y' : 'N';

#3

Thanks :slight_smile:


#4

As I looked at the code the instruction says "Set the canDrive variable equal to the ternary expression: (fuelLevel > 0) ? 'Y' : 'N';" My issue was I set fuelLevel > 1 not 0. Hope this helps