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
Subtract two numbers using method overriding Program 1
PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…
Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…
Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…
Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…
How to write a program to convert Fahrenheit into Celsius In this article, we will…
This website uses cookies.