Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions

Question

How does a freemium business model work?

Answered: 1 week ago