Trace and document every step of execution of the following program:
public class Trace {
public static void main(String[] args) {
int[] num = {1, 3, 6, 9, 12 };
for (int i = 4; i >= 0; i--)
{
num[i]
+=1;
}
num[0]
*=num[4];
}
}
well simply first understand that in the for loop simply all the number are
being incremented by 1 starting from the last index to first .
Now the new num array is num = {2,4,7,10,13 }
then at the end 1st element is changed by its multiplication with the last element
and hence num[0] =2*13=26;
hence final array num ={26,4,7,10,13}
Also you can see this window as confirmation
if u have any query feel free to ask and please like my answer
Get Answers For Free
Most questions answered within 1 hours.