2
2
3
3
class arr_cls {
4
4
public static void main (String [] a ){
5
+
5
6
// Declaring an array here
6
7
int arr [];
7
8
@@ -61,5 +62,50 @@ public static void main(String[] a){
61
62
System .out .print (arr1 [i ] + " " );
62
63
}
63
64
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 ("\n Elements 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 };
64
110
}
65
111
}
0 commit comments