-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray MEthod.java
More file actions
34 lines (30 loc) · 1.12 KB
/
Array MEthod.java
File metadata and controls
34 lines (30 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
package com.company;
public class cwh_array2 {
public static void main(String[] args) {
int[] marks = {11, 33, 44, 66, 77, 88};
System.out.println("Printing using NAive Method");
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]);
System.out.println(marks[5]);
//Display Array in Simple way
//array Traversal
// Displaying the Array (for loop)
System.out.println("Printing using for loop");
for (int i = 0; i < marks.length; i++) {
System.out.println(marks[i]);
}
// Quick Quiz: Displaying the Array in Reverse order (for loop)
System.out.println("Printing using for loop in reverse order");
for (int i = marks.length - 1; i >= 0; i--) {
System.out.println(marks[i]);
}
// Display the element in For EAch loop
System.out.println("Printing using for each loop ");
for (int Element : marks){
System.out.println(Element);
}
}
}