幫助理解遞迴,以及遞迴返回值的處理
阿新 • • 發佈:2019-02-19
public class digui { private static int big = 10; public static Integer rand(){ Random random = new Random(); int i = random.nextInt(100); return i; } public static Integer digui(){ Integer s = null; Integer rand = rand(); Integer a = 0; if(rand%3==0){ s = rand; return s; }else if(rand%3!=0){ if(big>0){//不包含0 big--; a = digui(); System.out.println(a); } }else{ a = 100000; return a; } System.out.println(s); return a; } @Test public void invoke(){ Integer digui = digui(); System.out.println(digui); } }
能夠很好的幫助理解遞迴和java的底層——壓棧和彈棧的流程