首页 > 其他 > 详细

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

时间:2016-03-19 19:14:53      阅读:188      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!