Ternary Conditional


#1

Hello, My name is Jamel and I don't understand the instructions on #9 in the Learn Java Module. The instructions say:

1.
Set the canDrive variable equal to the ternary expression: (fuelLevel > 0) ? 'Y' : 'N';

I wrote the following code:

public class Ternary {
public static void main(String[] args) {

	int fuelLevel = 3;

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

}

}

I get the error;
Did you set canDrive equal to the result of the ternary expression? You can use the example to help you.

What is the program asking me to do? I don't get it.


#2

Uhm, for whatever reason the error does not come up any more and all I did was copy and paste (fuelLevel > 0)?'Y':'N'; after the variable and now it is showing fine. So go figure! Thanks anyway guys!


#3

Have you tried putting a space before and after the ?


#4

Thank you Judy! @albionsrefuge You just taught me something and that will keep me from making that mistake again. Thank you again.


#5

I don't know if you need the spaces in real life, maybe the code checker here just wants to see them. They do make it more readable.


#7