fill in the table to trace the values as they are passed from main and changed in the method.
For each part below, fill in the table to trace the values as they are passed from main and changed in the method.
a.
int [] array = {1,2,3,4,5};
int x = 12;
int y = doOne(array,x);
int [ ] array2 = {1,2,3,4,5};
int w = doOne(array2, array2[3]);
} // end of main
public static int doOne(int[] arr, int x){
for (int i=0; i<arr.length-1; i++)
arr[i] = arr[i]*arr[i+1];
x = x+3;
return x;
}
x in main before call to doOne
|
|
array in main before call to doOne
|
|
arr in doOne before loop
|
|
x in doOne before loop
|
|
arr in doOne after loop
|
|
x in doOne after loop
|
|
x in main after call to doOne
|
|
y in main after call to doOne
|
|
array in main after call to doOne
|
|
array2 in main before call to doOne
|
|
arr in doOne before loop
|
|
x in doOne before loop
|
|
arr in doOne after loop
|
|
x in doOne after loop
|
|
w in main after call to doOne
|
|
array2 in main after call to doOne
|
|
b.
int [] array3 = {1,2,3,4,5};
int s = 12;
int v = 32;
int [] num = doTwo(array3, v,s);
} // end of main
public static int[] doTwo(int[] arr, int x, int y){
int[] ret = new int[2];
x = arr[2] ;
y = arr[3] ;
ret[0] = x+arr[1];
ret[1] = y-arr[0];
return ret;
}
array3 before call to doTwo
|
|
s before call to doTwo
|
|
v before call to doTwo
|
|
arr in doTwo
|
|
x in doTwo
|
|
y in doTwo
|
|
ret in doTwo
|
|
array3 in main after call to doTwo
|
|
num in main after call to doTwo
|
|
s in main after call to doTwo
|
|
v in main after call to doTwo:
|
|
Trending now
This is a popular solution!
Step by step
Solved in 2 steps