-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathForEachLoopDemo.java
More file actions
46 lines (32 loc) · 1.12 KB
/
ForEachLoopDemo.java
File metadata and controls
46 lines (32 loc) · 1.12 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
44
45
46
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:
// Use a for-each loop to print each student name
for (String student : students){
System.out.println(student);
}
System.out.println("\nPrinting students in uppercase:");
// TODO:
// Use a for-each loop to print each name in uppercase
for (String student : students){
System.out.println(student.toUpperCase());
}
System.out.println("\nCount the number of students:");
int count = 0;
// TODO:
// Use a for-each loop to count how many students are in the list
for (String student : students){
count++;
}
System.out.println("Total students: " + count);
}
}