Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. Write an iterative method, and a recursive method that takes as input an integer n greater than 1 , and prints integers n through
5. Write an iterative method, and a recursive method that takes as input an integer n greater than 1 , and prints integers n through 1 one per line. For example, if the input is 4 , the output must be 4321 6. Write a recursive method int gcd( int x, int y ), that returns the greatest common divisor of x and y, which is defined recursively as follows:If y is equal to 0 , then gcd(x,y) is x; otherwise gcd(x,y) is gcd(y,x%y), where % is the modulus operator. 7. Write a recursive method that produces exactly the same output as the following iterative method static void iterative fn(intn){ for (int i=n;i>0;i){ System.out.println(i); \}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started