Computer Science, asked by faiqpalegar9886, 2 days ago

public class Test {
public static void main(String args[]) {
int a[ ] (5,1, 7);
int sum = 0;
for (int i=0; i<a.length; i+=2) {
sum = sum + a[i];
i--;
}
h
System.out.print (sum);
)​

Answers

Answered by sanjayrockstarsanjay
3

Answer:

please ask your question properly da bro

Answered by jubin22sl
1

Answer: The code prints the sum of array members 5,1,7 which equals 13.

Note: For correct output in for loop i-- should be equal to i++ else there will be a runtime error.

Explanation:

  • a[0] = 5, a[1] = 1, a[2] = 7
  • iteration will run for 3 times
  • 1'st iteration sum = 0 + 5 = 5
  • 2'nd time sum = 5 + 1 = 6
  • 3'rd time sum = 6 + 7 = 13
  • therefore in the end output = sum = 13

Similar questions