Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Euclid
- {
- public static void main (String[] argv)
- {
- int num1 = 22;
- int num2 = 11;
- DivisorCalc euclid = new DivisorCalc();
- System.out.println("The GCD of " + num1 + " and " + num2 + " is: " + euclid.gcd(num1, num2));
- }
- }
- class DivisorCalc
- {
- public int gcd (int num1, int num2)
- {
- //This if statement checks the condition of largest integers which divides both values without producing a remainder
- if (num2 <= num1 && num1 % num2 == 0)
- {
- return num2;
- }
- else
- {
- if (num1 < num2)
- {
- return gcd (num2, num1);
- }
- else
- {
- return gcd (num2, num1 % num2);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement