![](/img/trans.png)
[英]Why a method main.replay() is not getting executed in Java? But exactly the same code works in Fedora not in Archlinux
[英]Why is main method not getting called same no. of times recursively in java every time it is executed?
當我試圖運行這個程序幾次的最終值i
是11407
, 11417
, 11400
顯示堆棧溢出錯誤之前等。 為什么每次執行該程序時i
的最終值都不相同?
public class MainRecursive {
static int i=0;
public static void main (String arg[])
{
i++;
System.out.println(i);
main(arg);
}
}
嘗試添加System.out.flush();
印刷后。
由於堆棧大小沒有變化,每次運行時我得到相同的值,但我認為println()
在異常更新輸出之前被異常中斷 - 這取決於控制台,操作系統等而不能是確定性的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.