Program requirements: Read into the user input of the two integers K1 and K2 (K2>K1), and then output K1 and K2 gcd.
Reference program:
Import Java.util.Scanner;
public class P02 {public
static void Main (String arg[])
{
int k1,k2;
k1=0;
k2=0;
while (K1>=K2)
{
Scanner scan=new Scanner (system.in);
SYSTEM.OUT.PRINTLN ("Please input K1");
K1=scan.nextint ();
SYSTEM.OUT.PRINTLN ("Please input K2");
K2=scan.nextint ();
if (K1>=K2)
System.out.println ("input error");
}
System.out.println ("OK");
System.out.println ();
for (i=2;i<=k1;i++)
{
if (k1%i==0&&k2%i==0)
a=i
}
System.out.println ("K1 and K2 gcd are: " +a);
}
Train of thought: first, we have to determine whether the input of two of the composite requirements, that is, K2>K1, and then according to the Euclidean method of thinking to find the number of the Convention on the line.
Run Result: