- Java Basic Programs
- Java Programming Examples
- Java Print Hello World
- Java Get Input from User
- Java Print Integer
- Java Add two Numbers
- Java Check Even or Odd
- Java Check Prime or Not
- Java Check Alphabet or Not
- Java Check Vowel or Not
- Check Reverse equal Original
- Java Fahrenheit to Celsius
- Java Celsius to Fahrenheit
- Java Perfect Number Program
- Java Find Quotient Remainder
- Java Days to Seconds
- Java Count Digits in Number
- Java Binary Number Addition
- Java Discount Program
- Java Compute Courier Charge
- Java Find Telephone Bill
- Java Print ASCII Values
- Java Check Palindrome or Not
- Java Check Armstrong or Not
- Generate Armstrong Numbers
- Add two Numbers using Pointers
- Java Mathematical Programs
- Add Subtract Multiply & Divide
- Java Make Calculator
- Java Add Digits of Number
- Java Check Leap Year or Not
- Java Check Divisibility
- Java Find Simple Interest
- Java Find Compound Interest
- Java Print Fibonacci Series
- Java Find nCr nPr
- Calculate Average & Percentage
- Java Calculate Arithmetic Mean
- Java Calculate Student Grade
- Java Print Table of Number
- Java Print Prime Numbers
- Java Add n Numbers
- Java Interchange two Numbers
- Java Reverse Numbers
- Java Swap two Numbers
- Count Positive Negative & Zero
- Find Largest of two Numbers
- Find Largest of three Numbers
- Java Find Factorial of Number
- Java Find HCF & LCM
- Area & Perimeter of Square
- Area & Perimeter of Rectangle
- Area & Circumference of Circle
- Java Conversion Programs
- Java Decimal to Binary
- Java Decimal to Octal
- Java Decimal to Hexadecimal
- Java Binary to Decimal
- Java Binary to Octal
- Java Binary to Hexadecimal
- Java Octal to Decimal
- Java Octal to Binary
- Java Octal to Hexadecimal
- Java Hexadecimal to Decimal
- Java Hexadecimal to Binary
- Java Hexadecimal to Octal
- Java Pattern Programs
- Java Pattern of Stars
- Java Pattern of Alphabets
- Java Pattern of Numbers
- Java Pyramid of Stars
- Java Pyramid of Alphabets
- Java Pyramid of Numbers
- Java Print Diamond Pattern
- Java Print Floyd Triangle
- Java Print Pascal Triangle
- Java Array Programs
- One Dimensional Array Program
- Java Linear Search
- Java Binary Search
- Find Largest Element in Array
- Find Smallest Element in Array
- Java Reverse Array
- Insert Element in Array
- Delete Element from Array
- Java Merge two Array
- Java Bubble Sort
- Java Selection Sort
- Java Insertion Sort
- Java Find Common Elements
- Java Count Even/Odd Number
- Two Dimensional Array Program
- Java Add two Matrices
- Java Subtract two Matrices
- Java Transpose Matrix
- Multiply two Matrices
- Three Dimension Array Program
- Java String Programs
- Java Print String
- Find Length of String
- Java Compare two String
- Java Copy String
- Java Concatenate String
- Java Reverse String
- Delete Vowels from String
- Delete Words from Sentence
- Find Occurrence of a Character
- Java Find Occurrence of a Word
- Occurrence of Each Character
- Java Occurrence of Each Word
- Java Count Repeated Characters
- Java Count Repeated Words
- Java Capitalize Each Word
- Java Count Vowels/Consonants
- Java Extract Numbers
- Java Count Word in String
- Remove Spaces from String
- Java Sort a String
- Java Uppercase to Lowercase
- Java Lowercase to Uppercase
- Java Swap two Strings
- Java Check Anagram or Not
- Java Check Balance Parentheses
- Java Check Password Strength
- Java File Programs
- Java Read File
- Java Write to File
- Read & Display File Content
- Java Copy File
- Java Append Text to File
- Java Merge two File
- List files in Directory
- Java Delete File
- Java Miscellaneous Programs
- Generate Random Numbers
- Java Print Time & Date
- Java Get IP Address
- Java Shutdown Computer
- Java Programming Tutorial
- Java Tutorial
- Java Interview Questions
- Java Interview Questions
- Java Programming Test
- Java Programming Test
- Give Online Test
- All Test List

# Java Three Dimensional Array Program

This article is created to cover a program in Java based on three-dimensional array.

A three dimensional array can be said as an array of array of array. For example:

arr[2][3][4]

is a three dimensional array, where there is a two two-dimensional array, and each two dimensional array contains three one dimensional array, where there are 4 elements in each one dimensional array.

In other words, we can say that the array **arr** contains 4 elements of 3 array of 2 array. Total of
**2*3*4** elements, that is **24** elements. Here is an example:

public class CodesCracker { public static void main(String[] args) { int[][][] arr = { { {1, 2, 3, 4},{5, 6, 7, 8},{9, 10, 11, 12} }, { {13, 14, 15, 16},{17, 18, 19, 20},{21, 22, 23, 24} }}; for(int i=0; i<2; i++) { for(int j=0; j<3; j++) { for(int k=0; k<4; k++) { System.out.print("arr["+i+"]["+j+"]["+k+"] = " +arr[i][j][k]+"\t"); } System.out.print("\n"); } } } }

The snapshot given below shows the sample output produced by above program on three-dimensional array in Java:

As you can clearly see from the above program and its sample output, there are two 2D array, where each 2D array is of 3 1D array, where each 1D array is of 4 elements.

Three dimensional array is little complicated concept in programming, that contains three loops. So to print or to initialize elements to a three dimensional array, you need to use three loops. Where the innermost loop makes one dimensional array, the second innermost loop makes two dimensional array, and the outer loop makes finally the three dimensional array.

Here is another program, that allows user to define the size of dimension of three dimensional array, along with its elements:

import java.util.Scanner; public class CodesCracker { public static void main(String[] args) { int one, two, three, i, j, k; Scanner scan = new Scanner(System.in); System.out.println("---Enter the Size of Dimensions---\n"); System.out.print("How many elements to store in each 1D array: "); one = scan.nextInt(); System.out.print("How many 1D array to create: "); two = scan.nextInt(); System.out.print("How many 2D array to create: "); three = scan.nextInt(); int[][][] arr = new int[three][two][one]; System.out.print("\nEnter " +(one*two*three)+ " Elements for 3D Array: "); for(i=0; i<three; i++) { for(j=0; j<two; j++) { for(k=0; k<one; k++) arr[i][j][k] = scan.nextInt(); } } System.out.println("\nThe elements with its indexes are: "); for(i=0; i<three; i++) { for(j=0; j<two; j++) { for(k=0; k<one; k++) System.out.print("arr["+i+"]["+j+"]["+k+"] = " +arr[i][j][k]+"\t"); System.out.print("\n"); } } } }

Here is its sample run with user input **3** as number of elements to store in each one dimensional array, **2**
as number of one dimensional array to create, **3** as number of two dimensional array to create, and
**1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18** as eighteen elements for the three dimensional array:

#### Same Program in Other Languages

« Previous Program Next Program »

Like/Share Us on Facebook 😋