Description:
Find the GCD using the Euclidean algorithm.
Find the GCD using the Euclidean algorithm.
Java Code
public class GCD {
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static void main(String[] args) {
System.out.println("GCD of 48 and 18: " + gcd(48, 18));
}
}
Expected Output
GCD of 48 and 18: 6