Exercise 12.2.pdf - 5/25/2021...

This preview shows page 1 out of 1 page.

5/25/20211/1Success!The call sum_again( 5 );returned 15, that is correctReturn to ExercisesYour Code ( with color highlights added ):public int sum_again (int sum) { if ( sum > 0 ) { return sum + sum_again (sum - 1); } else { return sum; } }The Instructions:Exercise 12.2 :Recursive Summation Recursively calculate the SUM of a number, so SUM(5) = 5 + 4 + 3 + 2 + 1 = 15Write a 'public int' method named sum_againthat recursively calls itselfOne integer parameter named sumand it returns the summation value
End of preview. Want to read the entire page?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Addition, Recursion, Subroutine, Summation, Control flow, call sum

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture