• 寻找最大公因数和最小公倍数


    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

  • 相关阅读:
    SQL盲注工具BBQSQL
    嗅探X-Windows服务按键工具xspy
    多协议底层攻击工具Yesinia
    LLMNR欺骗工具Responder
    Arduino可穿戴教程保存源文件与打开已经存在的源文件
    GRDB使用SQLite的WAL模式
    CString之GetBuffer与ReleaseBuffer
    VC++ 模块与资源分离
    KV6.60 SP1
    Html之head部分详解
  • 原文地址:https://www.cnblogs.com/infinite14/p/8783387.html
Copyright © 2020-2023  润新知