标签:java io ar sp ad on c return rom
Recursion.
/** * sum from 1 to n. recursion * @param i * @return sum */ public int recur_head(int i){ System.out.println("i = "+ i); if(i==1) return 1; else return i+recur_head(i-1); }
tail Recursion.
/*** * sum from 1 to n. tail recursion * @param i * @param total * @return */ public int recur_tail(int i, int total){ System.out.println("i = "+ i+", total = "+ total); if (i == 1) return 1+total; return recur_tail(i-1, total +i); }
标签:java io ar sp ad on c return rom
原文地址:http://my.oschina.net/u/1767744/blog/305910