Ask Question
7 December, 08:38

Refer to the following code segment. You may assume that array arr1 contains elements arr1[0], arr[1], ..., arr[N-1], where N = arr1. length int count = 0; for (int i = 0; i < N; i++) if (arr1[i]! = 0) { arr1[count] = arr1[i]; count++; } int[] arr2 = new int[count]; for (int i = 0; i < count; i++) arr2[i] = arr1[i]; If arr1 initially contains the elements 0, 6, 0, 4, 0, 0, 2 in this order, what will arr2 contain after the execution of the code segment?

+3
Answers (1)
  1. 7 December, 08:42
    0
    6, 4, 2 will be contained by the arr2.

    Explanation:

    In the following code execution the integer array variable "arr2" contain 6, 4, 2 elements because in the code, set integer type variable "count" and initialize to 0 then, set the for loop which starts from 0 and end at length of the array variable "arr1" then, set the if conditional statement and check condition the variable "arr1" is not equal to 0 then, the value of the variable "arr1" initialize in the variable "arr2".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Refer to the following code segment. You may assume that array arr1 contains elements arr1[0], arr[1], ..., arr[N-1], where N = arr1. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers