-
Notifications
You must be signed in to change notification settings - Fork 701
Expand file tree
/
Copy pathEnhancedForLoops.java
More file actions
31 lines (25 loc) · 886 Bytes
/
EnhancedForLoops.java
File metadata and controls
31 lines (25 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package _03_07b;
import java.util.Arrays;
import java.util.List;
public class EnhancedForLoops {
public static void main(String[] args) {
int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 };
// Write an enhanced for loop to print out each prime number in the array.
for (int value : primeNumbers) {
System.out.println(value);
}
List<String> weekDays = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday");
// Write an enhanced for loop to print out each week day in the list.
for (String day : weekDays) {
System.out.println(day);
}
int[] randomNumbers = { 23, 51, 72, 84, 1, 60, 34, 102 };
// Write an enhanced for loop to print out the numbers in the array that are
// greater than 50.
for (int value : randomNumbers) {
if (value > 50) {
System.out.println(value);
}
}
}
}