Question: JAVA netbeans Given two positive integers i and j , the greatest common divisor of i and j , written gcd (i, j) is the

JAVA netbeans

Given two positive integers i and j, the greatest common divisor of i and j, written

gcd (i, j) is the largest integer k that divides both of them without remainder

(i.e. i % k = 0 and j % k = 0).

For example, gcd (35, 21) = 7 and gcd (8, 15) = 1.

According to Euclid's algorithm, the greatest common divisor (gcd) id defined as follows:

of i and j is j if i % j = 0. Otherwise, the greatest common divisor of i and j is the greatest common divisor of j and (i % j).

gcd (i, j)= j if i%j is equal to 0

gcd (i, j)= gcd(j, i%j) if i%j is not equal to 0

1. Develop a recursive method that returns the greatest common divisor of i and j.

Here is the method specification:

public static int gcd (int i, int j)

This method finds and returns the greatest common divisor of i and j.

1. Develop and run a test program to test your method.

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!