Answers to Self-Test Questions
-
B R R R
Note that the
'B'
is the first output, not the last output. -
R R R B
Note that the
'B'
is the last output. -
/** Precondition: n >= 1. Displays the symbol '#' n times on one line and then advances to the next line. */ public static void displaySharps(int n) { if (n <= 1) System.out.println('#'); else { System.out.print('#'); displaySharps(n − 1); } }
4. 6
-
/** Precondition: n >= 0 Returns 10 to the power n. */ public static int computeTenToThe(int n) { if (n <= 0) return 1; else return computeTenToThe(n − 1) * 10; }
-
/** Precondition: n can be any int. Returns 10 to the power n. */ public static int computeTenToThe(int n) { if (n == 0) return 1; else if (n > 0) return computeTenToThe(n − ...
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.