Need help on ternary conditionals :/


#1

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


#2

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';
	System.out.println(canDrive);

#3

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)

Or:

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

Do you see how these ternary operators work now?


#4

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.