Simple & Easy Solution using Java


#1

public class Solution {
public int gcd(int A, int B) {
int maxa=1;

    if(A==B){
        return A;
    }
    if(A==0&&B!=0){
        return B;
    }
    if(A!=0&&B==0){
        return A;
    }
    int c=Math.min(A,B);
    for(int i=2;i<=c;i++){
        if(A%i==0&&B%i==0){
            if(i>1){
                maxa=i;
            }
        }
    }
    return maxa;
}

}