Ternary.java

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

    int fuelLevel =0;

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

}

}
what am I doing wrong ? It does in fact run on the console but i get an error message stating have I set .Set the canDrive variable equal to the ternary expression: (fuelLevel > 0) ? ‘Y’ : ‘N’;
please give me some idea… thanks

1 Like

Not able to reproduce this error, even using your exact code. Perhaps refresh the page and try again.

I haven’t tested this, but maybe try to get all the spaces exactly like the error is asking for.

That’s the issue. I used the exact code, spacing and all, with no error. Puzzling…

Yes, I agree …

Did you try setting fuelLevel equal to something greater than 0? Maybe that’s the issue?

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

	int fuelLevel = 3;

char canDrive = (fuellevel > 0) ? ‘Y’ : ‘N’;
System.Out.Println(canDrive);

}

}
I am getting error for an infinite loop
Please suggest what is wrong

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

int fuelLevel = 3;

char canDrive = (fuellevel > 0) ? ‘Y’ : ‘N’;
System.Out.Println(canDrive);

}
}
I am getting error for an infinite loop
Please suggest what is wrong

Infinite loop? I don’t think so.

Here:

(fuellevel > 0) ? 'Y' : 'N';

variable fuellevel is not defined, it must be fuelLevel.


Java is case sensitive, find next problems without our help.

2 Likes

Java is case sensitive. Just try to find this without our help. There are two problems in the line number 6.

i found out … I am new to this case sensitiveness … Anyways thanks a lot .

Add spaces after every word in the ternary operator…
like this canDrive = (fuelLevel>0) ? ‘Y’ : ‘N’ ;
Hope this will work…

1 Like

That works, thank you!

A post was split to a new topic: unable to move ahead in this exercise

A post was split to a new topic: I don’t know what I’m doing wrong