GCD of two no.s

PLease see once what is the error in my code

Hey @ananyakulshrestha21
for (int i = 1; i <= n1 && i <= n2; i++) {
if (n1 % i == 0 && n2 % i == 0) {
gcd = i;
System.out.println(gcd);
}

	}

//These things are wrong
Let us consider some of the examples to find highest common factor (H.C.F) by using division method.

Figure

@ananyakulshrestha21

public static int gcd(int dividend, int divisor){

    while(dividend % divisor != 0){
        int rem = dividend % divisor;
        dividend = divisor;
        divisor = rem;
    }

    return divisor;
    }

dry run this logic