• 软件测试第二实验三作业(求最大公约数)


    package divisormax;

    import java.util.Scanner;

    public class Demo {

     /**
      * @param args
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      Scanner s=new Scanner(System.in);
      System.out.println("请输入两个整数");
      int a=1;
      int b=1;
      try {
       a=s.nextInt ();
       b=s.nextInt();
      } catch (Exception e) {
       // TODO: handle exception
       System.out.println("您输入不是数字无法求公约数!");
      }
      
      MaxDivisor m=new MaxDivisor(a,b);
     }

    }

    package divisormax;

    public class MaxDivisor{
     int min;
     int herf=0;
     
     
     public  MaxDivisor(int a,int b){
      if(a>b)
      {
       min=b;
      }
      else
      {
       min=a;
      }
      
      for(int i=1;i<=min;i++)
      {
       if(min%i==0)
       {
        if(((a+b)-min)%i==0)
        {
         herf=i;
        }
       }
      }
      System.out.println(herf);
     }
     
    }

  • 相关阅读:
    第八讲、原型模式
    第七讲、建造者模式
    第六讲、抽象工厂模式
    第五讲、工厂方法模式
    第四讲、简单工厂模式
    第三讲、策略模式
    第二讲、备忘录模式
    第一讲、单例模式
    二、中国黑客
    java 17
  • 原文地址:https://www.cnblogs.com/hpj1038361347/p/5353534.html
Copyright © 2020-2023  润新知