谁能帮我从这里的评论中为以下代码绘制运行时堆栈?我尝试了这个,但被告知这是不正确的,我的教授拒绝解释这个......如果有人能给我一个例子,很容易将它用作另一段代码的比较。具体来说,我相信我没有正确格式化堆栈。
我的尝试:
array a initialized with 3 values
integer x = 4;
call method b, passes in array a.
integer i = 14;
array x[0] = 4;
call method e, passes in i - 2 = 12;
calls method f 12 - 4 = 8;
int j = 2;
8 * 2 = 16;
println "16";
println "4 + 0"
public class RuntimeStack
{
public static void main (String [] args)
{
int[] a = new int[3];
int x = 4;
b(a);
System.out.println(a[0] + “ “ + a[1] + “ “ + x);
}
public static void e(int a)
{
f(a-4);
// HERE! }
public static void b(int [] x)
{
int i = 14;
x[0] = 4;
e(i-2);
}
public static void f(int i)
{
int j = 2;
System.out.println("i * j = " + (i * j));
}
} // end class RuntimeStack
非常感谢!