Conditional operators

These are another way, more compact way of doing if else statements.

class jamesprogram {

	public static void main(String args[]){
		int banana=37;

		System.out.println(banana>20 ? "More than 20" : "Less than 20");

The above logic means if there’s more than 20 bananas do the first thing, else do the second thing.

Leave a Reply