Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given the following method: public int dunno(int m) { int value; if (m == 0) val

ID: 3608340 • Letter: G

Question

Given the following method: public int dunno(int m) {       int value;       if (m == 0)             value= 3;       else             value= dunno(m - 1) + 3;       returnvalue; } What is the output produced by the followingstatement? System.out.println(dunno(3)); Given the following method: public int dunno(int m) {       int value;       if (m == 0)             value= 3;       else             value= dunno(m - 1) + 3;       returnvalue; } What is the output produced by the followingstatement? System.out.println(dunno(3));

Explanation / Answer


dunno(2) will call value = dunno(1) + 3

dunno(1) will call value = dunno(0) + 3
dunno(0) will have m == 0 so it will return 3
so dunno(1) will return 6, and likewise dunno(2) will return 9and dunno(3) will return 12
So it will print "12". It looks like dunno(x) in generalcalculates 3 * (x + 1).
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote