Error on ternary conditions

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);

	}
}

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.

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

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