Can anyone help me draw the run time stack from the comment HERE for the following code? I attempted this, but was told it was incorrect, and my professor refused to explain this.... If anyone can give me an example, it will be easy to use that as a comparison for another piece of code. Specifically I believe I am not formatting the stack correctly.
My attempt:
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
Thank you very much!