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).
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.