February 2017
Beginner
1056 pages
28h 57m
English
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 − ...Read now
Unlock full access