| .-------------. | statement 1 | `-------------' | .-------------. | statement 2 | `-------------' | .-------------. | statement 3 | `-------------' |
double side = in.getDouble(); double volume = side * side * side; System.out.println("Volume of cube: " + volume);
| /--------\ < decision > \--------/ / \ true false / \ .-----------. .-------------. | statement | | alternative | `-----------' `-------------' | | `------------------' |
if test then actions otherwise actions
if speed - limit > 15 then fine = $300 penalty = 2 points otherwise fine = $100 penalty = 1 point
if ( test ) { statements } else { statements }
int speed, limit, fine, penalty; // ... if ( speed - limit > RECKLESS ) { fine = 300; penalty = 2; } else { fine = 100; penalty = 1; }
if ( test ) { statements } else { statements }
if score >= 93 grade = "A" else if score >= 89 grade = "AB" else if score >= 85 grade = "B" else if score >= 81 grade = "BC" else if score >= 77 grade = "C" else grade = "need to repeat"
String grade; if ( score >= 93.0 ) { grade = "A"; } else { if ( score >= 89.0 ) { grade = "AB"; } else { if ( score >= 85.0 ) { grade = "B"; } else { if ( score >= 81.0 ) { grade = "BC"; } else { if ( score >= 77.0 ) { grade = "C"; } else { grade = "need to repeat"; } } } } }
String grade; if ( score >= 93.0 ) { grade = "A"; } else if ( score >= 89.0 ) { grade = "AB"; } else if ( score >= 85.0 ) { grade = "B"; } else if ( score >= 81.0 ) { grade = "BC"; } else if ( score >= 77.0 ) { grade = "C"; } else { grade = "need to repeat"; }
if answer matches expected response, then print message saying answer right add 1 to number of correct scores otherwise print message giving correct answer
boolean isLess; isLess = 4 * 3 < 2 * 5;
int speed, limit, fine, penalty; boolean driving_recklessly; // ... // not a really good method: driving_recklessly = speed - limit > RECKLESS; if ( driving_recklessly ) { fine = 300; penalty = 2; } else { fine = 100; penalty = 1; }
if time >= 900 and time <= 1700, then print ticket otherwise print warning
if ( time >= 900 && time <= 1700 ) { System.out.println("Speeding; pay $300."); } else { System.out.println("Warning: drive more carefully!"); }
if speed > limit or time = 1700, then print ticket otherwise, print "drive safely"
if ( speed > limit || time == 1700 ) { System.out.println("Speeding; pay $300."); } else { System.out.println("Drive safely"); }
if not(time >= 900 and time <= 1700), then print warning otherwise print ticket
if ( !(time >= 900 && time <= 1700) ) { System.out.println("Warning: drive more carefully!"); } else { System.out.println("Speeding; pay $300."); }
if ( time >= 900 && time <= 1700 ) { System.out.println("Speeding; pay $300."); }
if ( time >= 900 && time <= 1700 ) System.out.println("Speeding; pay $300.");
if ( time >= 900 && time <= 1700 ) System.out.println("Speeding;"); System.out.println("pay $300.");
if ( speed > limit ) { if ( speed - limit > RECKLESS ) System.out.println("Pay $300"); else System.out.println("Pay $100"); }
if ( speed > limit ) if ( speed - limit > RECKLESS ) System.out.println("Pay $300"); else System.out.println("Pay $100");