208k views
3 votes
Java Array question, thank you for your help!::

Give the contents of the val array after running the following code:

int [] val = { 3, 10, 44 };
int i = 0;
val[i] = val[i + 1];
i++;
val[i] = val[i + 1];
Question options:

1) 0 1 44

2) 0 2 44

3) 1 2 44

4) 3 3 3

5) 3 0 0

6) 3 3 10

7) 10 44 44

User Sree KS
by
6.0k points

1 Answer

4 votes

Answer:

7) 10 44 44

Step-by-step explanation:

So, you have your initial array consisting of: 3, 10, 44

The number 3 is in position 0.

So, on line 2, you initialize i with value 0;

Then you assign to the position of i (0) of the array the value of the position next to it.

So, your array now includes: 10, 10, 44

You increase the value of i by 1 (to 1) and do another similar assignation.

So, your array now includes: 10, 44, 44

User Avinash Sonee
by
7.3k points