Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class EuclideanTheorem {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner sc = new Scanner(System.in);
- System.out.println("Enter two numbers to compute GCD : ");
- int x = sc.nextInt();
- int y = sc.nextInt();
- outer: while (true) {
- if (x > y) {
- x %= y;
- if (x == 0) {
- System.out.println("THE GCD is :" + y);
- break outer;
- }
- } else {
- y %= x;
- if (y == 0) {
- System.out.println("THE GCD is :" + x);
- break outer;
- }
- }
- }
- }
- }
- /*
- OUTPUT :
- Enter two numbers to compute GCD :
- 8765
- 23485
- THE GCD is :5
- */
Advertisement
Add Comment
Please, Sign In to add comment