Problem in java ternary


#1

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

	int fuelLevel = 3;

	char canDrive 
	System.out.println(canDrive);

}

}

instruction:
Set the canDrive variable equal to the ternary expression: (fuelLevel > 0) ? 'Y' : 'N';

but i can not understand


#2

This means that the variable canDrive will be the result of evaluating if the variable 'fuelLevel' is greater than 0, based on that the value to set will be 'Y' if true and 'N' if false.

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


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.