Skip to content

Commit 66b490a

Browse files
committed
Overview of Array Completed
1 parent 0804693 commit 66b490a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

arr_cls.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class arr_cls{
44
public static void main(String[] a){
5+
56
// Declaring an array here
67
int arr[];
78

@@ -61,5 +62,50 @@ public static void main(String[] a){
6162
System.out.print(arr1[i] + " ");
6263
}
6364
System.out.println();
65+
66+
// Passing the arrays to the function
67+
sum(arr);
68+
69+
// Cloning Multidimensional Array
70+
int[][] array3 = array2.clone();
71+
72+
System.out.println("Elements of Multidimensional Array : ");
73+
for(int i = 0;i < array3.length;i++){
74+
for(int j = 0;j < array3[0].length;j++){
75+
System.out.print(array3[i][j] + " ");
76+
}
77+
System.out.println();
78+
}
79+
80+
// Returning array from the methods or functions
81+
int[] array4 = arr1();
82+
System.out.println("\nElements of the array that is created by returning from a method : ");
83+
for(int i = 0;i < array4.length;i++){
84+
System.out.print(array4[i] + " ");
85+
}
86+
System.out.println();
87+
88+
// Creating Class Objects for Arrays
89+
byte[] bytearray = new byte[3];
90+
short[] shortarray = new short[3];
91+
String[] string_array = new String[3];
92+
93+
// Printing the data to the user
94+
System.out.println("Class of first bytearray created : " + bytearray.getClass());
95+
System.out.println("Class of second shortarray created : " + shortarray.getClass());
96+
System.out.println("Class of third string_array created : " + string_array.getClass());
97+
System.out.println("SuperClass of third string_array created : " + string_array.getClass().getSuperclass());
98+
}
99+
100+
public static void sum(int[] a){
101+
int result = 0;
102+
for(int i = 0;i < a.length;i++){
103+
result += a[i];
104+
}
105+
System.out.println("Sum of all the digits of the array is : " + result);
106+
}
107+
108+
public static int[] arr1(){
109+
return new int[] {34,55,65};
64110
}
65111
}

0 commit comments

Comments
 (0)