-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paththreeDarray.java
57 lines (53 loc) · 1.48 KB
/
threeDarray.java
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.*;
public class threeDarray
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int l=0; //length of cubiod
int b=0; //breadth of cubiod
int h=0; //height of cubiod
System.out.println("Enter the size of the 3d array");
l = input.nextInt();
b = input.nextInt();
h = input.nextInt();
//decalring 3d array
int[][][] arr = new int[l][b][h];
getArray(arr,l,b,h);
printArray(arr, l, b, h);
input.close();
}
public static void getArray(int[][][] array,int x,int y,int z)
{
System.out.println("Enter the elements of 3d array");
Scanner in = new Scanner(System.in);
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
for(int k=0;k<z;k++)
{
array[i][j][k] = in.nextInt();
}
}
}
in.close();
}
public static void printArray(int[][][] array,int x,int y,int z)
{
System.out.println("Your 3d array");
for(int i=0;i<x;i++)
{
for(int j=0;j<y;j++)
{
System.out.print("| ");
for(int k=0;k<z;k++)
{
System.out.print(array[i][j][k]+" ");
}
System.out.println("|");
}
System.out.println("-------------------");
}
}
}