Question: JAVA: public class test3 { public static void main (String[] argv) { int[] A = { 1, 1, 1, 1 }; for(int i = 0;

JAVA: 
public class test3 { public static void main (String[] argv) { int[] A = { 1, 1, 1, 1 }; for(int i = 0; i < 4; ++i) { for(int j = i-1; j >=0; --j) { A[i] += A[j]; } } for(int i = 0; i < 4; ++i) System.out.println(A[i]); } }

Perform a paper and pencil trace of the specified code. Execute the program as if you are the CPU and state the output exactly as if the computer exectued it. You must be able to successfully answer these types of questions using a paper and a pencil!

For example: In the first iteration of the loop, the value of someVariable1 is blah blah, the value of someVariable2 is blah blah. In the second iteration of the loop, the value of someVariable1 is.....

By doing this for the first two or three iterations, you should be able to generalize and then give a couple of sentences, what you expect the final answer (if any?) to be. If the loop does not terminate, that is it runs in an infinite loop, then explain why do you think that is the case.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!