Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,003 questions

51,950 answers

573 users

How to create 3D array in Java

1 Answer

0 votes
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) throws Exception {
        int[][][] arr = new int[2][3][4];
         
        arr[0][0][0] = 11;
        arr[1][1][1] = 32; 
        arr[0][2][2] = 99;
        arr[0][1][3] = 44;
        arr[1][2][3] = 55;
 
        for (int depth = 0; depth < 4; depth++) {     
            for (int row = 0; row < 2; row++) {
                for (int col = 0; col < 3; col++) {         
                    System.out.printf("%d ", arr[row][col][depth]);        
                }
                System.out.println();      
            }      
            System.out.println();    
        }
    }
}
 
 
 
/*
run:
 
11 0 0 
0 0 0 

0 0 0 
0 32 0 

0 0 99 
0 0 0 

0 44 0 
0 0 55 

*/

 



answered Aug 29, 2020 by avibootz
edited Jan 14, 2022 by avibootz

Related questions

1 answer 95 views
1 answer 156 views
156 views asked Jan 14, 2022 by avibootz
1 answer 165 views
3 answers 272 views
2 answers 192 views
1 answer 101 views
1 answer 111 views
...