655
10.Given the following input:
15
23
21
19
What is the output of the following method?
public voidprintNums()
{
intn;
String line;
line = inFile.readLine();
if(line != null) // If not EOF ...
{
n = Integer.parseInt(line);
outFile.print(n + " ");
printNums();
outFile.print(n + " ");
}
}
Programming Warm-Up Exercises
1.Write a Java value-returning method that implements the recursive formula
f(n) = f(n1) + f(n2) with base cases of f(0) = 1 and f(1) = 1.
2.Add whatever is necessary to fix the following method so that func( 3 ) equals
10.
public static intfunc(intn)
{
returnfunc(n – 1 ) + 3 ;
}
3.Rewrite the following printSquaresmethod using recursion.
public static voidprintSquares()
{
intcount;
for(count = 1 ; count <= 10 ; count++)
outFile.println(count + " "+ count * count);
}