Here is my code.
import java.util.*;
public class GCD
{
public static void main (String args [] )
{
Scanner reader = new Scanner(System.in);
int a, b, x, d = 0, c = 0;
String response;
do
{
System.out.println("Please enter first number to find GCD.");
a = reader.nextInt();
System.out.println("Please enter second number to find GCD.");
b = reader.nextInt();
for (x = a-1; x>=1; x--)
{
c = a%x;
if (c==0)
{
d = b%x;
if (d==c)
{
break;
}
}
}
System.out.println(x);
System.out.println("Would you like to go again?");
response = reader.nextLine();
response = reader.nextLine();
}while ( response.equals("yes") );
System.out.println("Have a nice day.");
}
}
Why doesn't it work. We haven't learned the methods so we have to use loops. Can anyone help me out?
import java.util.*;
public class GCD
{
public static void main (String args [] )
{
Scanner reader = new Scanner(System.in);
int a, b, x, d = 0, c = 0;
String response;
do
{
System.out.println("Please enter first number to find GCD.");
a = reader.nextInt();
System.out.println("Please enter second number to find GCD.");
b = reader.nextInt();
for (x = a-1; x>=1; x--)
{
c = a%x;
if (c==0)
{
d = b%x;
if (d==c)
{
break;
}
}
}
System.out.println(x);
System.out.println("Would you like to go again?");
response = reader.nextLine();
response = reader.nextLine();
}while ( response.equals("yes") );
System.out.println("Have a nice day.");
}
}
Why doesn't it work. We haven't learned the methods so we have to use loops. Can anyone help me out?


