forked from ParthMurge/Java-Codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcwh_27_Display_Array.java
More file actions
37 lines (28 loc) · 1.17 KB
/
cwh_27_Display_Array.java
File metadata and controls
37 lines (28 loc) · 1.17 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
package company;
public class cwh_27_Display_Array {
public static void main(String[] args){
int [] marks = {20, 40, 56, 65, 92};
// Dislaying the array using Naive Way:
System.out.println("Displaying the array using Naive Way:");
System.out.println(marks[0]);
System.out.println(marks[1]);
System.out.println(marks[2]);
System.out.println(marks[3]);
System.out.println(marks[4]);
// Displaying the array using for loop:
System.out.println("Displaying the array using for loop:");
for(int i = 0; i < marks.length; i++){
System.out.println(marks[i]);
}
// Displaying the array using for loop (in reverse order):
System.out.println("Displaying the array using for loop (in reverse order):");
for(int i = (marks.length-1); i >= 0; i--){
System.out.println(marks[i]);
}
// Displaying the array using for-each loop:
System.out.println("Displaying the array using for-each loop:");
for(int element : marks){
System.out.println(element);
}
}
}