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.

39,851 questions

51,772 answers

573 users

How to declare, initialize and print two-dimensional (2D) array of integers in Java

3 Answers

0 votes
package javaapplication1;

public class Example {
    public static void main(String[] args) {
             
        int[][] array2D = {{   234, 65, 99  }, 
			               { 34564, 12,  3 }};
	
        for (int[] array1D : array2D) {
            for (int item : array1D) {
                System.out.print(item + " ");
            }
            System.out.println();
        }
    }
}


/*
run:
 
234 65 99 
34564 12 3 
 
*/

 



answered Jan 16, 2016 by avibootz
edited Oct 8, 2016 by avibootz
0 votes
package javaapplication1;

public class Example {
    public static void main(String[] args) {
             
        int[][] array2D = {{   234, 65, 99 }, 
			               { 34564, 12,  3 }};
	
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) 
                System.out.println("array2D[" + i + "][" + j + "] = " + array2D[i][j]);
        }
    }
}


/*
run:
 
array2D[0][0] = 234
array2D[0][1] = 65
array2D[0][2] = 99
array2D[1][0] = 34564
array2D[1][1] = 12
array2D[1][2] = 3
 
*/

 



answered Jan 16, 2016 by avibootz
edited Oct 8, 2016 by avibootz
0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        int[][] array2D = {{   234, 65, 99 }, 
                           { 34564, 12,  3 }};
     
        for (int i = 0; i < 2; i++ ) {
            for (int j = 0; j < 3; j++ ) {
                System.out.print(array2D[i][j] + " ");
            }
            System.out.println();
        }
    }
}
 
/*

run:

234 65 99 
34564 12 3 

*/

 



answered Oct 8, 2016 by avibootz
...