Question: Write a recursive method that accepts an integer n and prints the first n positive integers to the Java console. For example: n, (n 1),

Write a recursive method that accepts an integer n and prints the first n positive integers to the Java console. For example:

n, (n 1), (n 2), ..., 3, 2, 1

For example, if n = 10, then the following would be printed to the Java console:

10 9 8 7 6 5 4 3 2 1

2. Write a recursive method that accepts an integer n and prints all multiples of 3 from n down to 3.

For example, if I was given n = 20 then I would send the following output to the Java console:

18 15 12 9 6 3

Note: do not assume that n begins as a multiple of 3

3. 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

4. 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!