Leave a Reply 7

Your email address will not be published. Required fields are marked *


Ryan

Ryan

I don’t feel like typing this one out. Answer is A – 20.

obrain

obrain

int[] lst = {1,2,3,4,5,4,3,2,1};
int sum=0;
for (int frnt=0, rear=lst.lenght – 1;frnt =5; frnt++, rear–) {
sum = sum + lst[frnt] + lst[rear];
}
System.out.print(sum);

1 1 = 2
2 2 = 4
3 3 = 6
4 4 = 8

A. 20

nisha

nisha

What is the exit condition for this for loop?
frnt=5 is not a conditional statement

jackson

jackson

whether frnt=5 cause compilation error

renko

renko

Answer:
A
Code question:
public class Main {

public static void main(String[] args) {
int[] lst = {1,2,3,4,5,4,3,2,1};
int sum=0;
for (int frnt=0, rear=lst.length – 1;
frnt = 5;
rnt++, rear–) {
sum = sum + lst[frnt] + lst[rear];
}
System.out.print(sum);
}

}
Output:
20