Question: Task# 2 Create a Java program that asks the user to enter a number and uses a recursive function to print all numbers in ascending

Task# 2

Create a Java program that asks the user to enter a number and uses a recursive function to print all numbers in ascending order up to the given (entered) number.

For example:

Enter Number? 7

1 2 3 4 5 6 7

Task# 3

Create a Java program that generate the following series using recursive function.

100 200 300 400 500 600 700 800 900 1000

Task# 4

Printing a string backwards can be done iteratively or recursively. To do it recursively, think of the following specification:

If S contains any characters (i.e., is not the empty string)

  • print the last character in S
  • print S string in backwards

The program prompts the user for a string, and then calls method printBackwards method to print the string backwards. The printBackwards methods prints the string in backwards using the recursive strategy outlined above

Task# 5

Factorial Function: You have probably seen the factorial function before. It is defined for all integers greater or equal to zero:

For example,

factorial( 5 ) = 5 * factorial( 4 )

= 5 * ( 4 * factorial( 3 ) )

= 5 * ( 4 * (3 * factorial( 2 ) ) )

= 5 * ( 4 * (3 * (2 * factorial( 1 ) ) ) )

= 5 * ( 4 * (3 * (2 * ( 1 * factorial( 0 ) ) ) ) )

= 5 * ( 4 * (3 * (2 * ( 1 * 1 ) ) ) )

factorial( 0 ) = 1 // Base Case

factorial( N ) = N * factorial( N-1 ) // Recursive Case

= 5 * 4 * 3 * 2 * 1 * 1 = 120

Often factorial(N) is written as N!

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!