Skip to content

Commit 0804693

Browse files
committed
Array Data Type Added
1 parent a39c019 commit 0804693

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

arr_cls.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import java.util.Scanner;
2+
3+
class arr_cls{
4+
public static void main(String[] a){
5+
// Declaring an array here
6+
int arr[];
7+
8+
// Allocating the memory space to it
9+
arr = new int[5];
10+
11+
// for taking input
12+
Scanner scn = new Scanner(System.in);
13+
14+
// Initialising the values of the array
15+
for(int i = 0;i < arr.length;i++){ // length keyword to get the length of the array
16+
System.out.print("Enter a value for the element : ");
17+
arr[i] = scn.nextInt();
18+
}
19+
System.out.println();
20+
21+
// Declaring an Array Literal
22+
int[] array1 = new int[]{1,2,3,4,5,6,7};
23+
24+
System.out.print("Elements of an Array Literal : ");
25+
// Iterating over this Array
26+
for(int i = 0;i < array1.length;i++){
27+
System.out.print(array1[i] + " ");
28+
}
29+
System.out.println();
30+
31+
// Defininga Multidimensional Array
32+
int[][] array2 = new int[3][3];
33+
34+
// Getting the Rows and Columns of the Array
35+
System.out.println("Rows of the Array : " + array2.length);
36+
System.out.println("Column of the Array : " + array2[0].length);
37+
38+
// Initiating a Multi-Dimensional Array
39+
for(int i = 0;i < array2.length;i++){
40+
for(int j = 0;j < array2[0].length;j++){
41+
System.out.print("Enter an element : ");
42+
array2[i][j] = scn.nextInt();
43+
}
44+
System.out.println();
45+
}
46+
scn.close();
47+
48+
// Iterating over to the Array
49+
System.out.println("Element of the Array are mentioned below : ");
50+
for(int i = 0;i < array2.length;i++){
51+
for(int j = 0;j < array2[0].length;j++){
52+
System.out.print(array2[i][j] + " ");
53+
}
54+
System.out.println();
55+
}
56+
57+
// Cloning of 1D Array
58+
int[] arr1 = arr.clone();
59+
System.out.println("Printing the Array which is cloned : ");
60+
for(int i = 0;i < arr1.length;i++){
61+
System.out.print(arr1[i] + " ");
62+
}
63+
System.out.println();
64+
}
65+
}

0 commit comments

Comments
 (0)