Need help on ternary conditionals :/


I don't understand it, i'd appreciate some help, it would be awesome if someone could help over skype.


same here .. jus twhen i thought i was getting the hang of it.. dont understand what the letters are for... i was able to answer it and it was successful but still was unable to understand completely why was it that it worked

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

	int fuelLevel = 3;

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


This part is asking the question, "Is fuelLevel > 0?"

These are the two possible answers to that question. In this case they happen to be 'Y' and 'N', presumably standing for Yes / No.

How about:

(fuelLevel > 3) ? "keep driving" : "get fuel"

Another example:

if (fuelPrice > 1.00)  ? "cheap" : "expensive"

(I have no idea what fuel prices are)


if (temp > 0) ? "melt" : "freeze"  // Celsius
if (temp > 32) ? "melt" : "freeze"  // Fahrenheit

Do you see how these ternary operators work now?


I don't think there's anything wrong with your code, however it's weird that the text editor isn't accepting your answer. The way I managed to get past this round was just simply copying the answer code under the "Instructions" area and pasting it on the editor. It's the same exact answer with exception to spacing.