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 what(int m) { int temp; if ( m ==0 | | m

ID: 3608338 • Letter: G

Question

Given the following method: public int what(int m) {       int temp;       if ( m ==0  | | m == 1)             temp= 0;       else             temp= what(m - 2) + m;       System.out.println( "M= " + m);       returntemp; } what would the output be if the following statementwere executed? System.out.println(what(5)); Given the following method: public int what(int m) {       int temp;       if ( m ==0  | | m == 1)             temp= 0;       else             temp= what(m - 2) + m;       System.out.println( "M= " + m);       returntemp; } what would the output be if the following statementwere executed? System.out.println(what(5)); System.out.println(what(5));

Explanation / Answer


what(3) will call temp = what(1) + 3
what(1) will set temp = 0, and then it will print "M = 1" andreturn 0
what(3) will now set temp = 3, print "M = 3" and return3
what(5) will now set temp = 8, print "M = 5" and return8
The calling System.out.println will then print "8".
So all told it will print: M=1 M=3 M=5 8
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