Two number of inputs to the GCD Java applet __ Small Program

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.