RRB Junior Engineer / DMS / CMA 2019 · Question 3633 of 3719
The correct answer is option 2. Concept: An array in Java is an object that contains elements of the same data type. Furthermore, the items of an array are kept in a single memory address. It's a data structure where we save items that are comparable. In a Java array, we can only hold a fixed number of items. The given Java code is, public class SumOfArray { public static void main(String[ ] args) int [ ] arr = new int [ ] {1, 2, 3, 4}; int sum = 0; for (int i = 0; i < arr.length; i++) { sum = sum + arr[i]; } System.out.printIn("Sum of all the elements of an arry: " + sum); } } Explanation: "arr" is an integer array it has four elements like, arr[0]=1; arr[1]=2; arr[2]=3; arr[3]=4; And initially, the sum has zero, and each iteration of the for-loop adds to the sum. At end of the sum, the variable has added all elements in an integer arr of four elements. sum=1+2+3+4; And sum=10 Prints like Sum of all the elements of an array: 10 as output. Hence the correct answer is the S um of all the elements of an array: 10.
Source: RRB JE 2019 (CBT 2) (IT) Previous Year Paper (30 Aug 2019) — prepp.in solved-paper PDF (answer key with explanations) · reliable-secondary
Practice the full RRB Junior Engineer / DMS / CMA 2019 paper
Timed test with all 3719 questions, just like the real exam.
Start test