Error on ternary conditions


#1

Hi,
For ternary conditions, I am receiving error for more than one character on the condition results. Instead of Y I used “yes” and instead on N used “No”. I am receiving error.

public class Ternary {
	public static void main(String[] args) {
		
		int fuelLevel = 3;

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

	}
}

#2

The single quotations ‘_’ denote a char variable. Only a single character is allowed in this data type. “Yes” and “No” would be considered Strings and are denoted by double quotations. You will learn about them later.


#3

the error is about ur single quotation cause its just for a single character
:wink:


#4

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