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

What output is produced if the following method werecalled with the statement Sy

ID: 3608337 • Letter: W

Question

What output is produced if the following method werecalled with the statement System.out.print( question ( 3,5) );? public int question ( int k, int n) {          if(n == k)                returnk;          elseif (n > k)                returnquestion(k, n - k)          else                returnquestion(k - n,n); } What output is produced if the following method werecalled with the statement System.out.print( question ( 3,5) );? public int question ( int k, int n) {          if(n == k)                returnk;          elseif (n > k)                returnquestion(k, n - k)          else                returnquestion(k - n,n); }

Explanation / Answer

question(3,5) has n > k (because 5 > 3) so itreturns question (3, 2)
question(3, 2) has n < k (because 2 < 3) so it returnsquestion ( 1, 2)
question(1, 2) has n > k (because 2 > 1 ) so it returnsquestion(1, 1)
question(1, 1) has n == k so it returns 1.
It will then recurse back up to the top and return 1 so itwill simply print 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