Exercise 9 - Ternary


#1

cant understand whats wrong with this
public class Ternary {
public static void main(String[] args) {

	int fuelLevel = 3;

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

}

}


#2

@ajaxace52134,
Try it by using

		int fuelLevel = 3;

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

#3

is ternary a simple form of "if statement"


#4

@microcoder47419,
Doing a google search
== discussions / opinions ==
java is a ternary a substitute of an if statement site:stackoverflow.com
http://stackoverflow.com/questions/4706696/which-if-construct-is-faster-statement-or-ternary-operator
== the Book ==
ternary site:oracle.com
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html


#5

I tried that and the answer is wrong, also how is it different from what ajaxace52134 wrote?


#6

put a space after the question mark, it will work.


#7

I tried that and it worked, but its the same so im confused how it worked.