Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GCD {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Please enter a number: ");
- int a = scan.nextInt();
- System.out.print("Please enter a number: ");
- int b = scan.nextInt();
- System.out.println(gcd(a, b));
- }
- public static int gcd(int a, int b) {
- if (a < b) {
- int c = b;
- b = a;
- a = c;
- }
- while (a != 0 && b != 0) {
- int c = b;
- b = b % a;
- a = c;
- }
- return a + b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement