Quiz 4
Wednesday
With a piece of paper, write down your name and answers to the following questions.
Consider the following program?
public final class Program {
public static void main(final String[] args) {
System.out.println("mysteriousOne output:");
mysteriousOne(3);
System.out.println("mysteriousTwo output:");
mysteriousTwo(3);
System.out.println("mysteriousThree output:");
mysteriousThree(3);
}
private static void mysteriousOne(final int n) {
System.out.println(n);
if (n > 1)
mysteriousOne(n - 1);
}
private static void mysteriousTwo(final int n) {
if (n > 1)
mysteriousTwo(n - 1);
System.out.println(n);
}
private static void mysteriousThree(final int n) {
System.out.println(n);
if (n > 1)
mysteriousThree(n - 1);
System.out.println(n);
}
}What is the base case for the
mysteriousThreemethod?Answer:
n <= 1.What is the recursive case for the
mysteriousThreemethod?Answer:
n > 1.What is the output of this program?
Answer:
mysteriousOne output:
3
2
1
mysteriousTwo output:
1
2
3
mysteriousThree output:
3
2
1
1
2
3
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 4 on Wednesday.
A table showing the average performance for each question in Quiz 4 on Wednesday.
Friday
With a piece of paper, write down your name and answers to the following questions.
Consider the following program?
public final class Program {
public static void main(final String[] args) {
mysteriousTwo(3);
}
private static void mysteriousTwo(final int n) {
if (n < 1)
return;
mysteriousTwo(n - 1);
mysteriousOne(3);
}
private static void mysteriousOne(final int n) {
if (n <= 1) {
System.out.println("Hurrah");
return;
}
System.out.println("Hip");
mysteriousOne(n - 1);
}
}What is the base case for the
mysteriousOnemethod?Answer:
n <= 1.What is the recursive case for the
mysteriousOnemethod?Answer:
n > 1.What is the output of this program?
Answer:
Hip
Hip
Hurrah
Hip
Hip
Hurrah
Hip
Hip
Hurrah
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 4 on Friday.
A table showing the average performance for each question in Quiz 4 on Friday.