-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj28Array.java
More file actions
37 lines (27 loc) · 1 KB
/
j28Array.java
File metadata and controls
37 lines (27 loc) · 1 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
public class j28Array {
public static void main(String[] args){
// genrate array
int [] arr1; // Declaration
arr1 = new int [5]; // memory allocation
int [] arr2 = new int[5]; // Declaration + memory allocation
int [] arr3 = {1,2,3,4,5,6,7,8,9,0}; // declare + initialize
System.out.println(arr3[5]);
// Declare values in array 1
arr1[0] = 1;
arr1[1] = 3;
arr1[2] = 5;
arr1[3] = 7;
arr1[4] = 9;
// System.out.printf("\n\n %d %d %d %d %d " ,arr1[0] ,arr1[1] ,arr1[2] , arr1[3] ,arr1[4]);
// findlength of array
System.out.println("\nArray1 length is : "+arr1.length+"\n\n");
//print 1 by 1 arr 1
for(int i = 0 ; i < arr3.length; i++){
System.out.println(arr3[i]);
// print in reverse order
for (int j = arr3.length-1; j>=0; j--){
System.out.println(arr3[j]);
}
}
}
}