Skip to content

Commit 7891d52

Browse files
committed
added arrays\Enhanced_For_Loop.java
1 parent be7ff42 commit 7891d52

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

arrays/Enhanced_For_Loop.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package arrays;
2+
3+
public class Enhanced_For_Loop {
4+
5+
public static void main(String[] args) {
6+
7+
int array[]={3,4,5,6,7};
8+
int total=0;
9+
10+
for (int x: array) {
11+
total +=x;
12+
}
13+
System.out.println(total);
14+
15+
/*
16+
* Similar to last for loop
17+
* except that you have an identifier
18+
* so it's like saying that x = array
19+
* and it will add:
20+
* 1. 0 + 3
21+
* 2. 3 + 4
22+
* 3. 4 + 5
23+
* 4. 5 + 6
24+
* 5. 6 + 7
25+
* then the output is the total, 25
26+
*/
27+
28+
29+
}
30+
31+
}

0 commit comments

Comments
 (0)