Need programming help with a java question (((Output of arrays)))

Programming
Tutor: None Selected Time limit: 1 Day

1) List all values that the array ia will contain after the following code is executed:

    int[] ia = new int[10];

    ia[8] = 6;

    ia[4] = ia[8];

    ia[7] = 8;

    ia[3] = -30;

    ia[6] = 3;

    ia[2] = 6;

    ia[3] = 7;

    ia[5] = 2 * ia[4];

    ia[0] = 1;

    ia[1] = ia[0];

    int i = ia[6];

    ia[6] = 9;

    ia[i] = ia[4] * ia[8];

    ia[9] = 31;

Nov 15th, 2015

Thank you for the opportunity to help you with your question!

-----------------------------------------------------------------------------

int[] ia = new int[10];

So the array ia can store 10 integer values in ia[0] to ia[9].


Lets start with ia[0] and move forward.

ia[0] = 1;


ia[1] = ia[0];  

which means ia[1] = 1


ia[2] = 6;


ia[3] = -30;

But then it is changed to

ia[3] = 7; 

Again it is changed 

ia[6] = 3;

int i = ia[6]; // i = 3

ia[i] = ia[4] * ia[8]; //ia[3] = ia[4] * ia[8] = 6 * 6 = 36

which means ia[3] in the end will contain 36.


ia[8] = 6;

ia[4] = ia[8];

which means ia[4] = 6


ia[5] = 2 * ia[4];

which means ia[5] = 2 * 6 = 12


ia[6] = 3;

But then it is changed to

ia[6] = 9;


ia[7] = 8;


ia[8] = 6;


ia[9] = 31;


So the values that the array ia will contain after the following code is executed is

ia[0] = 1;

 ia[1] = 1

ia[2] = 6;

ia[3] = 36

ia[4] = 6

ia[5] = 12

ia[6] = 9;

ia[7] = 8;

ia[8] = 6;

ia[9] = 31;


-----------------------------------------------------------------------------

Please let me know if you need any clarification. I'm always happy to answer your questions.
Nov 15th, 2015

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Nov 15th, 2015
...
Nov 15th, 2015
Dec 9th, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer