Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ComputeGCD {
- /**
- * @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();
- while(x!=y) {
- if(x>y)
- x = x - y;
- else
- y = y - x;
- }
- System.out.println("The GCD is : "+x);
- }
- }
- /*
- OUTPUT :
- Enter two numbers to compute GCD :
- 8765
- 23485
- The GCD is : 5
- */
Advertisement
Add Comment
Please, Sign In to add comment