import java.util.scanner;public class test6 { //Euclidean Euclidean method &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;STATIC&NBSP;INT&NBSP;GCD (int a,int b) { int r ; while (b != 0) { r = a % b ; a = b; b = r; } return a; Another solution to } //least common multiple public static int gcdtwo ( INT&NBSP;A,INT&NBSP;B) { while (a != b) { if (a > b ) { a = a -b; } else { b = b - a; } } return a; } // Greatest common divisor &NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;STATIC&NBSP;INT&NBSP;LCM (int a,int b) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;RETURN&NBSP;A&NBSP;*&NBSP;B&NBSP;/GCD (A, b); } public static void main (String[] args) { sCanner input = new scanner (system.in); System.out.println ("Please enter first number:"); int a = Input.nextint (); system.out.println ("Please enter a second number:"); int b = input.nextint (); /*if (a < b) { a = a+b; b = a - b; a = a - b; }*/ system.out.println (Gcdtwo (b)); systEm.out.println (LCM (b)); }}
This article is from the "Orange Growth Record" blog, be sure to keep this source http://azhome.blog.51cto.com/9306775/1546770
Java inputs two positive integers m and N, seeking their greatest common divisor and least common multiple.