fork(1) download
  1. import java.io.*;
  2. import java.util.*;
  3. class GCD
  4. {
  5. public static void main(String args[])throws IOException
  6. {
  7. Scanner sc=new Scanner(System.in);
  8. System.out.println("Enter the numbers");
  9. int a=sc.nextInt();
  10. int b=sc.nextInt();
  11. System.out.println("GCD of a and b is "+gcd(a,b));
  12. }
  13. static int gcd(int a,int b)
  14. {
  15. if(a%b==0)
  16. return b;
  17. else
  18. return gcd(b,a%b);
  19. }
  20. }
Success #stdin #stdout 0.15s 321280KB
stdin
49 14
stdout
Enter the numbers
GCD of a and b is 7