Table of Contents
Program 1
Code segment
int[][][] age={{45,34,67,65},
{23,76,58,72},
{15,65,68,90},
};
class ArrayWithForThreeDim{
public static void main (String args[]){
int[][][] age={
{
{45,34,67},
{23,76,58},
{48,52,69},
},
{
{15,65,68},
{25,45,78},
{45,55,68},
}
};
System.out.print("\ndisplay cell value in an array: \n");
for(int i=0; i<=1; i++){
for(int j=0; j<=2; j++){
for(int k=0; k<=2; k++){
System.out.print("\ndisplay Element index["+i+"]["+j+"]["+k+"]: "+age[i][j][k] );
}
}
}
}
}
import java.util.Scanner;
class ThreeDimArray{
public static void main(String args[]){
int i,j,k;
Scanner scan=new Scanner(System.in);
int arr[][][]=new int[2][2][3];//array declaration
System.out.print("\nEnter the Element to three dim array: \n");
for(i=0; i<2; i++){
for(j=0; j<2; j++){
for(k=0; k<3; k++){
arr[i][j][k]=scan.nextInt();
}
}
}
System.out.print("\ndisplay Element in an array: \n");
for(i=0; i<2; i++){
for(j=0; j<2; j++){
for(k=0; k<3; k++){
System.out.print("\ndisplay Element["+i+"]["+j+"]["+k+"]:"+arr[i][j][k] );
}
}
}
}
} import java.util.Scanner;
class ThreeDimArray1{
public static void main(String args[]){
int i,j,k;
Scanner scan=new Scanner(System.in);
int arr[][][]=new int[2][2][3];//array declaration
System.out.print("\nEnter the Element to three dim array: \n");
i=0;
while(i<2){
j=0;
while(j<2){
k=0;
while(k<3){
arr[i][j][k]=scan.nextInt();
k++;
}
j++;
}
i++;
}
System.out.print("\ndisplay Element in an array: \n");
i=0;
while(i<2){
j=0;
while(j<2){
k=0;
while(k<3){
System.out.print("\ndisplay Element["+i+"]["+j+"]["+k+"]:"+arr[i][j][k] );
k++;
}
j++;
}
i++;
}
}
} When the above program is executed, it produces the following result
class ThreeDimArray2{
public static void main(String args[]){
int i,j,k;
Scanner scan=new Scanner(System.in);
int arr[][][]=new int[2][2][3];//array declaration
System.out.print("\nEnter the Element to three dim array: \n");
i=0;
do{
j=0;
do{
k=0;
do{
arr[i][j][k]=scan.nextInt();
k++;
} while(k<3);
j++;
} while(j<2);
i++;
}while(i<2);
System.out.print("\ndisplay Element in an array: \n");
i=0;
do{
j=0;
do{
k=0;
do{
System.out.print("\ndisplay Element["+i+"]["+j+"]["+k+"]:"+arr[i][j][k] );
k++;
}while(k<3);
j++;
}while(j<2);
i++;
}while(i<2);
}
} When the above program is executed, it produces the following result
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.