标签:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class qwe {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 0;
System.out.print("请输入m:");
BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
try {
a=Integer.parseInt(strin.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int b = 0;
System.out.print("请输入一个n:");
BufferedReader strin2=new BufferedReader(new InputStreamReader(System.in));
try {
b=Integer.parseInt(strin2.readLine());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int flag = 0;
for (int i = 1; i <= a; i++) {
if(a%i==0){
if(b%i==0){
flag=i;}
}
}
System.out.println("最大公约数为"+flag);
}
标签:
原文地址:http://www.cnblogs.com/shirongquan/p/5383630.html