码迷,mamicode.com
首页 > 其他好文 > 详细

求两个数的最大公约数与最小公倍数

时间:2016-03-19 19:17:23      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                    import java.util.*;

                    public class S{

                                public static void main(String[] args){  

                                           Scanner input = new Scanner(System.in);

                                           int num1,num2,remainder,m,n;  

                                           System.out.print("请输入一个正整数:");  

                                            num1 = input.nextInt();

 

                                            System.out.print("请再输入一个正整数:");

                                             num2 = input.nextInt();   m = num1;

                                             n = num2;

                                            if(num1>num2){  

                                                       remainder = num2;  

                                            }else{  

                                                       remainder = num1;

                                             }

                                             while (!(num1 % remainder ==0 && num2 % remainder == 0)){  

                                                        remainder--;

                                                }

                                                System.out.println("最大公约数是:"+remainder);  

                                                System.out.println("最小公倍数是:"+m*n/remainder);

                                     }

                               }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

求两个数的最大公约数与最小公倍数

标签:

原文地址:http://www.cnblogs.com/toaday/p/5295810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!