import java.util.Scanner; public class Gcd { public static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter two numbers: "); int a = scanner.nextInt(); int b = scanner.nextInt(); int result = gcd(a, b); System.out.println("GCD of " + a + " and " + b + " is: " + result); scanner.close(); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter