0

can anyone explain me the working

public class Program { public static void main(String[] args) {int [ ] myArr = {6, 42, 3, 7}; int sum=0; for(int x=0; x<myArr.length; x++) { sum += myArr[x]; } System.out.println(sum); // 58

12th Jun 2020, 10:04 PM
Diksha Jadhav
3 Answers
+ 2
for loop runs 4 times with x value increasing by 1 sum=sum+myArr[x] adds the value at index x to sum then
12th Jun 2020, 10:12 PM
Abhay
Abhay - avatar
0
sorry but i still did not get it can you please give a dry run with explaination please ?
12th Jun 2020, 10:34 PM
Diksha Jadhav