Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using java: - Create a class with a name RecursionConversion - Create a scanner object that be accessed by the entire class including the recursion

Using java:

- Create a class with a name RecursionConversion

- Create a scanner object that be accessed by the entire class including the recursion methods. I.e. create a static

scanner object before the public static void main.

- The scanner object will provide an input box to do the following prompts:

Enter a number for the factorial problem

Enter two numbers and Ill find the GCD

- Create a public-static-void-main where you will call reverseNumbers(), factorial() and GreatestCd() methods with

their respective parameters

- Create an integer array list with a variable name firstList and assign any integer values with a length not less than 5

and not more than 15

- Call the method named reverseNumbers and pass into it the integer array list firstList. Note, before you can call the

reverseNumbers method. Youre expected to have created function reverseNumbers outside of the main class.

- First task: To Print a list in reverse order

i. Hence, in creating the reverseNumbers method with a parameter number, write a condition that if the length of the array list number is equal to zero then return zero. If it is not equal to zero then call reverseNumbers recursive method but do it without the first element and reverse the rest of the list number. To do this recursive method part, you will need to create a new array list with a name secondList, copy the values of your number array (i.e. firstList) into the second array list (i.e. secondList). (Hint: you can use for loop to copy the values). And finally for this part, Call the recursive method reverseNumbers and pass into it the new or second array list secondList you created and print out the value values in the array starting at position 0

- Second task: Find the factorial of a natural number

i. In creating the factorial method, write a condition that if the variable integer torial1 is equal to 1 then return 1 but if the

number torial1 is not equal to 1 then return the multiplication of the number torial1 by recursive method

named factorial. (hint: this can be coded as factorial(torial1 -1);

- Third task: Find the greatest common divisor of two numbers

i. In creating the method named GreatestCd that will find the greatest common divisor, write a code to swap two integer

numbers first. Let the integer numbers variable names be num1 and num2

ii. Then write a condition that if you num1 is equal to 0 then return num1 but if num1 is not equal to 0 then return the

greatestCd recursive method and pass into it num2 along with reminder of num1 divided by num2.

Sample Output:

image text in transcribed

> run ecursionConveraion 120 105 S0 75 E0 45 30 15 Enter a number for the factorial problem: Factorial of 5 is: 24 Enter two nunhers and I'll find the GCD 7 14

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions