Tag: console output

在递归中使用+ =的Java和C ++中的不同结果

如下非常简单的Java代码具有奇怪的输出,但C和C ++中的相同逻辑代码具有正确的输出。 我尝试使用JDK 1.7和JDK 1.3(相对JRE),奇怪的输出始终存在。 public class Test { public static int sum=0; public static int fun(int n) { if (n == 1) return 1; else sum += fun(n – 1); // this statement leads to weird output // { // the following block has right output // int tmp = fun(n – 1); // […]