if (boolean expression is true) execute next statement.
{}
block multiple statements.>
: greater than<
: less than>=
: greater than or equal to<=
: less than or equal to==
: equal to!=
: not equal tox > y
: Is x greater than y?x < y
: Is x less than y?if (x > y) System.out.println("X is greater than Y");
if(x != y) { ... }
if (average > 95) grade = 'A';
{}
.if (expression) { statement1; statement2; }
if (average > 95) highScore = true;
if(c < 'Z') System.out.println("A is less than Z");
if (expression) statementOrBlockIfTrue; else statementOrBlockIfFalse;
if (expression_1) { ... } else if (expression_2) { ... } else { ... }
&&
) - Both conditions must be true.||
) - At least one condition must be true.!
) - Reverses the truth value.&&
.||
.equalsIgnoreCase
and compareToIgnoreCase
.%d
, %f
, and %s
.System.out.printf
, but returns formatted strings.