Question: Q1 1.Write a program that prompts the user to enter two integers and display their GCD. The gcd(m, n)can also be defined recursively as follows:

Q1

1.Write a program that prompts the user to enter two integers and display their GCD. The gcd(m, n)can also be defined recursively as follows:

a.If m % n is 0, gcd(m, n)is n

b.Otherwise, gcd(m, n) is gcd(n, m % n)

Your program should use a recursive methodto find the GCD and the output should be displayed as follows:

The program shall begin with the following code:

Enter the first integer integer: 17

Enter the second integer: 3The GCD of 17 and 3 is 1

import java.util.Scanner;

public class GCD{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

...............

.............

}

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!