Advertisement
Guest User

GCD

a guest
Nov 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. package individual_project2;
  2.  
  3. import java.math.BigInteger;
  4.  
  5. public class GCD {
  6.     //Default Constructor
  7.     public GCD(){
  8.     }
  9.     //GC Constructor which calls the gcd method to print the Greatest Common Divisor Number
  10.     //but only if both of the numbers are integer (check also InputOutput.class, Line 35)
  11.     public GCD(int a, int b){
  12.         gcd(a,b);
  13.     }
  14.     public void gcd(int a, int b){
  15.         BigInteger b1 = new BigInteger(""+a);
  16.         BigInteger b2 = new BigInteger(""+b);
  17.         BigInteger gcd = b1.gcd(b2);
  18.         System.out.println("The Greatest Common Divisor Number of " + a + " and " + b + " is: " + gcd.intValue());
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement