Skip to content

Commit 944a29f

Browse files
For Each Loop
1 parent 9001035 commit 944a29f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

27.For_Each_Loop/cwh_27_arrays.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.company;
2+
3+
public class cwh_27_arrays {
4+
public static void main(String[] args) {
5+
6+
/*
7+
float [] marks = {98.5f, 45.5f, 79.5f, 99.5f, 80.5f};
8+
String [] students ={"Harry", "Rohan", "Shubham", "Lovish"};
9+
System.out.println(students.length);
10+
System.out.println(students[2]);
11+
*/
12+
13+
int [] marks = {98, 45, 79, 99, 80};
14+
// System.out.println(marks.length);
15+
16+
// Displaying the Array (Naive way)
17+
System.out.println("Printing using Naive way");
18+
System.out.println(marks[0]);
19+
System.out.println(marks[1]);
20+
System.out.println(marks[2]);
21+
System.out.println(marks[3]);
22+
System.out.println(marks[4]);
23+
24+
// Displaying the Array (for loop)
25+
System.out.println("Printing using for loop");
26+
for(int i=0;i<marks.length;i++){
27+
System.out.println(marks[i]);
28+
}
29+
30+
// Quick Quiz: Displaying the Array in Reverse order (for loop)
31+
System.out.println("Printing using for loop in reverse order");
32+
for(int i=marks.length -1;i>=0;i--){
33+
System.out.println(marks[i]);
34+
}
35+
36+
// Quick Quiz: Displaying the Array (for-each loop)
37+
System.out.println("Printing using for-each loop");
38+
for(int element: marks){
39+
System.out.println(element);
40+
}
41+
42+
}
43+
}

0 commit comments

Comments
 (0)