Ask Question
27 June, 16:17

Assume that you have an array of integers named arr. Which of these code segments print the same results? int i = 0; while (i < arr. length) { System. out. println (arr[i]); i++; } int i; for (i = 0; i < = arr. length; i++) { System. out. println (arr[i]); } for (int i : arr) { System. out. println (i); }

+3
Answers (1)
  1. 27 June, 17:19
    0
    2. int i; for (i = 0; i < = arr. length; i++) { System. out. println (arr[i]); }

    3. for (int i : arr) { System. out. println (i); }

    second and third code segments print the same output.

    Explanation:

    In first code segment, while loop starts printing from arr[0] and it continues till the second last element of the the array as in statement of while loop i
    In second code, for loop starts from 0 and ends at the last element of the array. which prints from arr[0] to arr[length].

    In third code segment, it also print from arr[0] to arr[length]. In this case for (int i : arr) means start from first value of array and continues till last element of the array.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Assume that you have an array of integers named arr. Which of these code segments print the same results? int i = 0; while (i < arr. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers