嗯 ..就是..正规的递归应该有结束条件..
我举个求两个的最大公因子的递归方法.
import java.util.Scanner;
public class UseRecursion{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("输入两个数");
System.out.println("M=");
int m=scanner.nextInt();
System.out.println("N=");
int n = scanner.nextInt();
System.out.println("GCD:" + gcd(m,n));
}
private static int gcd(int m,int n){
if(n==0)
return m;
else
return gcd(n,m%n);
}
}