-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathForEachLoopDemo.java
More file actions
43 lines (31 loc) · 1.03 KB
/
ForEachLoopDemo.java
File metadata and controls
43 lines (31 loc) · 1.03 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
package Iterable.Examples;
import java.util.ArrayList;
import java.util.List;
public class ForEachLoopDemo {
public static void main(String[] args) {
List<String> students = new ArrayList<>();
students.add("Alex");
students.add("Jordan");
students.add("Taylor");
students.add("Morgan");
System.out.println("Printing students using a for-each loop:");
// TODO:
for (String x: students){
System.out.println(x);
}
System.out.println("\nPrinting students in uppercase:");
for (String x: students){
System.out.println(x.toUpperCase());
}
// TODO:
// Use a for-each loop to print each name in uppercase
System.out.println("\nCount the number of students:");
int count = 0;
for (String x: students){
count=students.size();
}
// TODO:
// Use a for-each loop to count how many students are in the list
System.out.println("Total students: " + count);
}
}