High School

Given that the integer array x has elements 5, 10, 15, 20, what is the output of the following code?

```java
int i;
for (i = 0; i < 4; ++i) {
System.out.print(x[i] + x[i + 1] + " ");
}
```

A. 15, 25, 35, 20
B. 10, 15, 20, 5
C. Out of range access
D. 15, 25, 35, 25

Answer :

Final answer:

The output of the given code is 15, 25, 35, 20.

Explanation:

The output of the given code is 15, 25, 35, 20.

The code is performing a loop that starts from index 0 and goes up to index 3. In each iteration of the loop, it prints the sum of the current element (x[i]) and the next element (x[i + 1]).

Here's how the output is calculated:
First iteration: 5 + 10 = 15
Second iteration: 10 + 15 = 25
Third iteration: 15 + 20 = 35
Fourth iteration: 20 + undefined (out of range access) = 20

Learn more about Array element sum here:

https://brainly.com/question/37199839

#SPJ11