-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTut9.java
More file actions
39 lines (33 loc) · 898 Bytes
/
Tut9.java
File metadata and controls
39 lines (33 loc) · 898 Bytes
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
package tutorial;
//Arrays
public class Tut9 {
public static void main(String[] args) {
// Array can be Declared in 2ways
int[] array1 = new int[4];
int[] arr = { 1, 2, 3, 4 };
// String arrays
String[] strarray = { "Prat", "Nid", "Dhan" };
// iterating array
System.out.println("Using for Loop");
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
// for each loop
System.out.println("Using For each Loop");
for (int i : arr) {
System.out.println(i);
}
System.out.println("Iterating String");
for (String s : strarray) {
System.out.println(s);
}
// creating 2d arrays
System.out.println("Created 2D Arrays");
int[][] arr2 = { { 1, 2, 3, 4 }, { 5, 6, 7, 7 } };
for (int i = 0; i < arr2.length; i++) {
for (int j = 0; j < arr2[i].length; j++) {
System.out.printf("arr2[%d][%d]=%d\n", i, j, arr2[i][j]);
}
}
}
}