102k views
16 votes
Given the code, what would you expect to happen as a result?

int[] lotteryNumbers = {7, 17, 27, 37, 47, 48};
lotteryNumbers[0] = 3;

a) an index out of bounds error

b) the arrays LAST element is set to 3

c) the arrays FIRST element is set to 3

d) array element 3 is set to 0

1 Answer

9 votes

Answer:

Option C) the array's first element is set to 3 is the correct answer.

Step-by-step explanation:

Given code is:

int[] lotteryNumbers = {7, 17, 27, 37, 47, 48};

lotteryNumbers[0] = 3;

The first line of code will make an array with the elements given on the right side of the equals to.

The elements of arrays are accessed through indexes and the indexes start from zero.

So,

lotteryNumbers[0] means the first element of array.

And

lotteryNumbers[0] = 3;

This means that the first element of array will be set to 3.

Hence,

Option C) the array's first element is set to 3 is the correct answer.

User Groffcole
by
4.9k points