import java.util.Scanner; public class Ok { // a method to find the greatest common divisor. // of given tv numbers. public static int GCD(int num1, int num2) { int gcd = 0, x = 0; if (num1 > num2) { x = num1 / num2; gcd = num1 - (num2 * x); } if (num2 > num1) { x = num2 / num1; gcd = num2 - (num2 * x); } return gcd; } public static void main(String[] args) { Scanner input = new Scanner(System.in); int num1, num2; System.out.println("Enter numer1:"); num1 = input.nextInt(); System.out.println("Enter number2:"); num2 = input.nextInt(); System.out.println("gcd=" + GCD(num1, num2)); } }
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