Relational operators
/*
* > : Greater Than
* < : Less Than
* == : Equal To
* != : Not Equal To
* >= : Greater Than Or Equal To
* <= : Less Than Or Equal To
*/
Logical operators
/*
* ! : Converts the boolean value to its right to its opposite form ie. true to false
* & : Returns true if boolean value on the right and left are both true (Always evaluates both boolean values)
* && : Returns true if boolean value on the right and left are both true (Stops evaluating after first false)
* | : Returns true if either boolean value on the right or left are true (Always evaluates both boolean values)
* || : Returns true if either boolean value on the right or left are true (Stops evaluating after first true)
* ^ : Returns true if there is 1 true and 1 false boolean value on the right or left
*/
Switch statement
char theGrade = 'B';
/*
* default code is executed if there are no matches
* You are not required to use the break or default statements
* The expression must be an int, short, byte, or char
*/
switch (theGrade)
{
case 'A':
System.out.println("Great Job");
break; // Ends the switch statement
case 'B':
System.out.println("Good Job, get an A next time");
break;
case 'C':
System.out.println("OK, but you can do better");
break;
default:
System.out.println("You failed");
break;
}
网友评论