Java program design: The maximum common divisor and the minimum common multiple.
Question: enter two positive integers, number1 and number2, to obtain the maximum common number and the minimum common number.
Algorithm: returns the remainder of a large number and a decimal number. The remainder of a decimal number is obtained until the remainder is 0, which is the maximum common divisor (moving phase division ); the maximum public factor numbe1 * number2/(the maximum public approx.). Run the following code:
Import java. util. secret; public class Max_Min {static int n1; public static void main (String [] args) {Max_Min m = new Max_Min ();/** enter two values here, obtain the minimum public multiple and maximum public approx. */Scanner s = new limit (System. in); System. out. print ("enter a positive Integer:"); int number1 = Integer. parseInt (s. nextLine (); System. out. print ("enter another positive Integer:"); int number2 = Integer. parseInt (s. nextLine (); if (number1> number2) {// here, if is used to filter out a large number. In the function, use m to obtain the remainder. function (number1, number2);} else {m. function (number2, number1);} m. function2 (number1, number2, n1); // This method returns the smallest public multiple} public void function (int number1, int number2) {if (number1% number2 = 0) {System. out. println ("maximum common approx.:" + number2); getInt (number2); // pass the maximum common approx. Value} else {function (number2, number1 % number2 );}} public void getInt (int number) {// obtain the maximum public approx. this. n1 = number;} public void function2 (int number1, int number2, int number) {// output the maximum public multiple System. out. println ("the maximum public factor is:" + number1 * number2/number );}}