Ask Question
12 March, 16:58

Which of these loops will initialize each element in the array ar to hold the value 4? A. for (int i = 1; i < ar. length; i++) ar[i] = 4;

B. for (int i = 0; i < = ar. length; i++) ar[i] = 4;

C. for (int i = 0; i < ar. length - 1; i++) ar[i] = 4; 0%

D. for (int i = 0; i < ar. length; i++) ar[i] = 4;

+1
Answers (1)
  1. 12 March, 17:34
    0
    Option (d) is correct.

    Explanation:

    In java language "ar. length" is used to tells the size of the array. The array is used to declare more than one variable. Its index value is started from 0. so when a user needs to initialize the value of an array, they need to start the index value at 0. because ar[0] indicates the first variable of an array.

    In option (d), index value is started from 0 and ends with (array_size-1). so it gives the accessed to all the variable of an array and the statement "ar[i]=4; ", initialize the value 4 to all array variable.

    while another option is not valid because--

    In option a, Index value starts from 1 which accesses the second variable of an array. In option b, the statement "i< = ar. length; ", gives an unbound array exception because it took the size greater than the array size. In option c, statement "i
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Which of these loops will initialize each element in the array ar to hold the value 4? A. for (int i = 1; i < ar. length; i++) ar[i] = 4; ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers