

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solutions for quiz 5 of c sc 227, which covers various recursion questions. It includes the return values for the 'mystery' and 'mysterytwo' methods, the output generated by 'mystery', 'stars', and 'recursive' methods, and the implementation of 'odddownevenup' and 'count8' and 'countx' methods as required by nick parlante javabat problems.
Typology: Quizzes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


____mystery(0) ___mystery(1) ____mystery(2) ____mystery(3) public int mystery(int n) { if (n <= 0) return 1; else return 3 + mystery(n - 1); }
______ mysteryTwo("T") ________ mysteryTwo("ab") ________ mysteryTwo("123") public String mysteryTwo(String s) { if (s.length() == 0) return ""; else return s.charAt(0) + "/" + mysteryTwo(s.substring(1)) ; }
public void mystery(String s, int digit) { if(digit <= 1) System.out.println(digit); else { s = s + "<"; mystery(s, digit - 2); System.out.println(s + digit); } }
stars(1) stars(2) stars(3) public void stars(int n) { if (n > 1) stars(n-1); for (int i = 0; i < n; i++) System.out.print("*"); System.out.println(); }