`

Java递归算法

 
阅读更多
public class A {
	
	public static int add(int x) {
		int y = 0;
		if (x ==  1) {
			return 5;
		} else {
			 y = add(x -1) + 1;
			 System.out.println("result" + x +"====>" + y);
			return y;
		}
	}
	
	
	public static int addAge(int x) {
		if (x ==  1) 
			return 5;
		else 
			return addAge(1) + x -1 ;
	}
	
	
	public static void main(String[] args) {
		int y = add(8);
		
		System.out.println(y);
		
	}

}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics