Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

Program to demonstrate three dimensional Array in Java

Program to demonstrate three dimensional Array in Java

import java.util.Scanner;

public class ThreeDimensionalArrayDemo {
   public static void main(String args[]) {

       Scanner input = new Scanner(System.in);
  
       int threeDArray[][][] = new int[10][10][10];
       int i = 0, j = 0, k = 0;
  
       System.out.print("Enter the value of i : "); 
       i = input.nextInt();

       System.out.print("Enter the value of j : "); 
       j = input.nextInt();
        
       System.out.print("Enter the value of k : "); 
       k = input.nextInt();
  
       System.out.println("");
  
       for(int m=0; m < i; m++) 
  for(int n=0; n < j; n++)
    for(int p=0; p < k; p++)
      threeDArray[m][n][p] = m * n * p;

       for(int m=0; m < i; m++) {
  for(int n=0; n < j; n++) {
    for(int p=0; p < k; p++) 
      System.out.print(threeDArray[m][n][p] + " "); 
    System.out.println();
  }
  System.out.println();
  }
       }
}

Output of the program : 


 
 
© 2021 Learn Java by Examples Template by Hubberspot