标签:style blog color java io ar div log
import java.io.IOException; import java.util.Scanner; public class CommonDivisor { public static void main(String[] args)throws IOException{ try{ System.out.println("请输入两个整数!"); Scanner input = new Scanner(System.in); int x = input.nextInt(); int y = input.nextInt(); System.out.println("两个整数的最大公约数为:" + gcd(x,y)); } catch(Exception ex){ System.out.println("需要输入的数为整数!"); } } public static int gcd(int m,int n){ int result = 0; if(m % n ==0){ result = n; } else result = gcd(n,m % n); return result; } }
用递归,求两个整数的最大公约数。
标签:style blog color java io ar div log
原文地址:http://www.cnblogs.com/Amoxicil/p/3912997.html