Greatest common divisor and least common multiple (Java) for two positive integers

Source: Internet
Author: User
Tags greatest common divisor

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

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.