Question: 1 Write a recursive method that accepts an integer n and returns the sum of the first n positive integers. 1 + 2 + 3

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!