Hey @Diya, here is a code on how you can achieve this,
public class GCD { //class name is GCD
static int gcd (int a, int b) //creating a function
{
if (b==0) // if b is 0 the gcd will be a
return a;
else
return gcd(b,a%b); // if b is not 0 then find the modulus and keep doing it till a%b becomes 0
}
public static void main(String[] args) //main method
{
int a =10 , b=4; //two variables
System.out.println(gcd (a,b)); //calling the function
}
}
Hope this helps.