Greatest Common Factor (GCD)

Given two numbers the task is to find the Greatest Common Factor or Highest Common Factor.

Example: 36 and 60 have a GCD of 12 since it is the only maximum number by which 36 and 60 both are divisible.

Java
import java.util.*;
public class GCD
{
    public static void main(String args[])
    {
        int n1=0,n2=0,min=0,gcd=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter two numbers:-");
        System.out.print("A: ");
        n1=sc.nextInt();
        System.out.print("B: ");
        n2=sc.nextInt();
        min=Math.min(n1,n2);
        for(int i=1;i<=min;i++)
        {
            if(n1%i==0&&n2%i==0)
            {
                gcd=i;
            }
        }
        System.out.println("GCD of "+n1+" and "+n2+" is: "+gcd);
    }
}
Java