Pin It

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 : 


 
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Related Posts Plugin for WordPress, Blogger...

Post your related queries below ...

comments powered by Disqus
Powered by Blogger.
 
© 2012 Learn Java by Examples Template by Hubber Spot