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

1 Write a recursive method that accepts an integer n and returns the sum of the

ID: 3788963 • Letter: 1

Question

1 Write a recursive method that accepts an integer n and returns the sum of the first n positive integers.

1 + 2 + 3 + + (n-2) + (n-1) + n

For example, if n = 5, then the method should return:

1 + 2 + 3 + 4 + 5 = 15

2. Write a recursive method that takes a String argument and recursively prints out each word in the String on a different line.

Note: You will need to use methods such as indexOf() and substring() within the String class to identify each word and the remaining string.

For example, if the input was “the cat purred”, then the method would print the following to the Java console:

the
cat
purred

Explanation / Answer

1)

Code: