Answers to Self-Test Questions
if (goals > 10) System.out.println("Wow"); else System.out.println("Oh Well");
if ((goals > 10) && (errors == 0)) System.out.println("Wow"); else System.out.println("Oh Well");
if (salary >= deductions) { System.out.println("OK"); net = salary - deductions; } else { System.out.println("No Way"); }
It is also acceptable to omit the braces in the
else
part.if ((speed > 25) && (visibility < 20)) { speed = 25; System.out.println("Caution"); }
if ((salary >= MIN_SALARY) || (bonus >= MIN_BONUS)) System.out.println("OK"); else System.out.println("Too low");
String upperWord = nextWord.toUpperCase(); if (upperWord.compareTo("N") < 0) System.out.println("First half of the alphabet"); else System.out.println("Second ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.