1 PackageCom.hpu.bai;2 3 ImportJava.util.Scanner;4 5 Public classCommon {6 Public intMincom (intMintN) {7 intTempintt = 0;8 if(m<N) {9temp =N;Tenn =m; Onem =temp; A } - if(m%n ==0)returnN; - Else the returnMincom (M-n,n); - } - Public intMaxcom (intMintN) { - returnm*n/mincom (m,n); + } - Public Static voidMain (string[] args) { +Common com =NewCommon (); AScanner input =NewScanner (system.in); atSYSTEM.OUT.PRINTLN ("The purpose of this program is to find a greatest common divisor of two positive integers"); -System.out.println ("Please enter first number"); - intm =input.nextint (); -System.out.println ("Please enter a second number"); - intn =input.nextint (); - intMax =com.maxcom (m,n); in intMin =com.mincom (m,n); -System.out.println ("M and N's greatest common divisor is" +max); toSystem.out.println ("M and N's least common multiple is" +min); + } - } theJava Beginner qq:623687677
Test result ok!
The purpose of this procedure is to find the greatest common divisor of two positive integers
Please enter the first number
90
Please enter the second number
20
The greatest common divisor of M and N is 180
The least common multiple of M and N is 10
Greatest common divisor and least common multiple (Java) for two positive integers