software_testing_work3_question1

 1 package com.Phantom;
 2 
 3 import java.io.IOException;
 4 import java.util.Scanner;
 5 
 6 public class Work3_1 {
 7     /**
 8      * @param args
 9      * @throws IOException 
10      */
11     public static void main(String[] args) throws IOException {
12         // TODO Auto-generated method stub
13         Scanner in=new Scanner(System.in);
14         System.out.println("请输入两个数字");
15         int num1=in.nextInt();
16         int num2=in.nextInt();
17         System.out.println("最大公约数为>>>"+operation(num1,num2));
18     }
19     public static int operation(int a,int b) throws IOException {
20         int num=0;
21         for(int i=1; i<=a; i++){
22             if(b%i==0&&a%i==0){
23                 num=i;
24             }
25         }
26         return num; 
27     }
28 }

运行结果:

findBugs:

原文地址:https://www.cnblogs.com/Phantom-void/p/5347509.html