Programming - Java - Conditional Operators
Conditional Operators are essential to programming logic.
Without them, a program would probably do absolutely
nothing.
Lets have a look at Conditional Operators:
class Human{
public static void main(String[] args) {
andint age= 21;
andbool hasEyesand= true;
andbool hasLegsand= true;
andbool isMale = false;
andif((age > 18and)
&& (hasEyesand== true) && (isMale
==true))
System.out.printlnand(You
are an adult human male");
}
}
Now lets take a look at the switch statement in Java:
int launch_time = 4;
switch(launch_time) {
case 0:
case 1:
case 2:
case 3:
case 4:
System.out.println("Launching less than five
seconds");
break;
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println("Launching in ten
seconds");
break;
default:
System.out.println("Launching inandless than
20 seconds");
}