Turn Desktop View Off
by Dinesh Thakur

 

import java.io.*;

class CommonDivisor
{
            int gcd(int m, int n)
            {
                        int r;
                        if (m < n) return gcd(n,m);
                        r = m%n;
                        if (r == 0) return(n);
                        else return(gcd(n,r));
            }
                        public static void main(String args[]) throws IOException
            {
                        CommonDivisor Divisor = new CommonDivisor();
                 BufferedReader BuffRead = new BufferedReader(new InputStreamReader(System.in));
                        String Num;
                        int a,b,Div;
                        System.out.print("Enter a Number :");
                        Num=BuffRead.readLine();
                        a=Integer.parseInt(Num);
                        System.out.print("Enter Another Number :");
                        Num=BuffRead.readLine();
                        b=Integer.parseInt(Num);
                        Div=Divisor.gcd(a,b);
                        System.out.print("The Greatest Common Divisor is "+Div);
            }
}

Greatest Common Divisor Using Recursion