有一個數學公式來計算遞歸函數被調用的次數爲下無需檢查與我的編譯計數遞歸調用
多少次會時與呼叫 mystery2調用mystery2遞歸調用(1000)?
public void mystery2(int n)
{
if (n <= 1)
System.out.print(n);
else
{
mystery2(n/2);
System.out.print(", " + n);
}
}
1,3,7,15,31,62,125,250,500,1000 = 10倍
實際上,靜態變量只初始化一次。 http://stackoverflow.com/questions/8943716/static-variable-in-method-call –