Skip to content

Commit 8b87f7a

Browse files
committed
feat: Demonstrate use of enhanced for loop with String and char arrays
🧠 Logic: - Create a `String` array `seasons` containing the four seasons. - Use an enhanced for loop (for-each) to iterate over the `seasons` array and print each season. - Define a `char` array `cardinalPoints` containing directional initials. - Use another enhanced for loop to print each direction character. - Emphasize the difference between characters (`'W'`) and strings (`"W"`). Signed-off-by: Somesh diwan <[email protected]>
1 parent a2c19bc commit 8b87f7a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Section8LoopAB/Loop 2.O/src/EnhancedForLoop.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
public class EnhancedForLoop
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class EnhancedForLoop {
2+
public static void main(String[] args) {
53
String[] seasons = new String[4];
64
seasons[0] = "Spring";
75
seasons[1] = "Summer";
@@ -11,7 +9,7 @@ public static void main(String[] args)
119
for (String season: seasons)
1210
System.out.println(season);
1311

14-
//Remember char are NOT Strings; notice the SINGLE QOUTES
12+
//Remember char are NOT Strings; notice the SINGLE QUOTES
1513
char[] cardinalPoints = {'W', 'N', 'E', 'S'};
1614

1715
for (char point: cardinalPoints)

0 commit comments

Comments
 (0)