zoukankan      html  css  js  c++  java
  • 寻找最大公因数和最小公倍数

    package 寻找公因数;
    import java.util.Scanner;
    public class 寻找公因数 {
     public static void main(String[] args) { 
            Scanner in = new Scanner(System.in); 
            System.out.print("input x :"); 
            int x = in.nextInt(); 
            System.out.print("input y :"); 
            int y = in.nextInt(); 
             
            int z = Method(x,y);  
            System.out.println("最大公因数 : "+z); 
            System.out.println("最小公倍数 : "+(x*y/z)); 
     }
             //计算公约数

    //辗转相除法
              public static int Method(int x,int y){ 
                  int a,b,c; 
                  a=x; 
                  b=y; 
                  while(b!=0){ 
                      c=a%b; 
                      a=b; 
                      b=c; 
                  } 
                  return a; 
              } 
            //求公倍数 
              public static int multiple(int x,int y){ 
                  int z; 
                  for(z=x;;z++){ 
                      if(z%x==0&&z%y==0){ 
                          break; 
                      } 
                  } 
                  return z; 
              } 
     
     }


      
           
         

    input x :3
    input y :5
    辗转相除法:
    最大公因数 : 1
    最小公倍数 : 15

  • 相关阅读:
    caffe杂
    easyui 扩展layout的方法,支持动态添加删除块
    easyui换主题,并记录在cookie
    $.messager.show扩展:指定位置显示
    easyui 扩展 之 Tree的simpleData加载
    easyui menu 添加hideItem/showItem 方法
    HTML标签及属性大全
    适应各种内核浏览器的透明修过样式
    让IE6支持min-width和max-width的方法
    javascript获取html标记的的绝对定位值
  • 原文地址:https://www.cnblogs.com/infinite14/p/8783387.html
Copyright © 2011-2022 走看看