Ternary Conditional

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

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';



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.

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!

Have you tried putting a space before and after the ?

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

1 Like

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.

1 Like