Advertisement
Guest User

Euclid

a guest
Apr 17th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Euclid
  4. {
  5. public static void main (String[] argv)
  6. {
  7. int num1 = 22;
  8. int num2 = 11;
  9. DivisorCalc euclid = new DivisorCalc();
  10. System.out.println("The GCD of " + num1 + " and " + num2 + " is: " + euclid.gcd(num1, num2));
  11. }
  12. }
  13.  
  14. class DivisorCalc
  15. {
  16. public int gcd (int num1, int num2)
  17. {
  18.  
  19. //This if statement checks the condition of largest integers which divides both values without producing a remainder
  20.  
  21. if (num2 <= num1 && num1 % num2 == 0)
  22. {
  23. return num2;
  24. }
  25. else
  26. {
  27. if (num1 < num2)
  28. {
  29. return gcd (num2, num1);
  30. }
  31. else
  32. {
  33. return gcd (num2, num1 % num2);
  34. }
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement