Create a Java file called GCD.java that find the greatest common divisor of two
ID: 3637990 • Letter: C
Question
Create a Java file called GCD.java that find the greatest common divisor of two positive integers Operation• The application prompts the user to enter two numbers. You can assume that the user will enter valid integers for both numbers.
• The application displays the greatest common divisor of the two numbers.
• The application prompts the user to continue.
Sample Run:
Greatest Common Divisor Finder
Enter first number: 12
Enter second number: 8
Greatest common divisor: 4
Continue? (y/n): y
Enter first number: 77
Enter second number: 33
Greatest common divisor: 11
Continue? (y/n): y
Enter first number: 441
Enter second number: 252
Greatest common divisor: 63
Continue? (y/n): n
Explanation / Answer
import java.util.*;
class GCD
{
public static void main(String[] args)
{
Scanner stdin = new Scanner(System.in);
int a,b;
char c;
System.out.println("Greatest Common Divisor Finder");
do
{
System.out.println("Enter first number: ");
a = stdin.nextInt();
System.out.println("Enter second number: ");
b = stdin.nextInt();
System.out.println(" Greatest common divisor: " + GCD(a,b));
System.out.println( "Continue? (y/n): y");
c = stdin.next();
}while(c.at(0) == 'y');
}
}