Question: 2. a) Write a recursive method called countDown(int n) that takes a single int parameter, n>=0, and displays a countdown. For example, countDown (10) would

2. a) Write a recursive method called countDown(int n) that takes a single int parameter, n>=0, and displays a countdown. For example, countDown (10) would display 10 9 8 7 6 5 4 3 2 1 BlastOff!

Write a main method that prompts the user to enter a positive integer n and counts down to 1 from n.

b) Modify the above method so that if n is even, it displays only even numbers in the countdown, whereas if n is odd, it displays only odd numbers in the countdown. For example, countDown(10) would print 10 8 6 4 2 BlastOff! and countdown(9) would print 9 7 5 3 1 BlastOff!

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!