Hello!
I am preparing for my exam. And I am doing some java exercises from the book. But here I have some problem. My answer does not match with the book's answer. Please explain what I am doing wrong.
here is the code:
public class EX5 {
public static void main (String [ ] args) {
int [ ] data = {6, 2, 5, 1, 10, 3, -3};
int result = 0;
for (int i = 2; i < data.length; i++) {
result = result + (data[i] - data[i-2]);
System.out.println("result = " + result);
}
}
}
the book answer is
result = -1
result = -2
result = 3
result = 5
result = -8
.
But my answer is :
-1
-1
5
2
-13
Best regards