Initialize Two dimensional Array

From Java Example Source Code

Jump to: navigation, search

Contents

[edit] Overview - Initialize Two dimensional Array

This Java example program indicate how to initialize 2D Array.

[edit] Java Source Code

  • Package: example.array
  • File: Test2Darray.java
  1. package example.array;
  2.  
  3. // A two dimensional array of int values is initialized, and the element
  4. // at [0][2] is displayed.
  5.  
  6. public class Test2Darray {
  7.     public static void main(String args[]) {
  8. 	int[][] multiD = { { 1, 2, 3, 4 }, { 5, 6, 7 } };
  9. 	System.out.println("The element at [0][2] is " + multiD[0][2]);
  10.     }
  11. }

[edit] What Result You Can Get

Run the program, you will get:

The element at [0][2] is 3

[edit] Required External Libraries and/or Files for this Java Example

Need nothing.


[edit] How to Run this Java Example Program

We recommend running this Java example program with Eclipse.

For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.

It's fairly easy.



[edit] Question & Answer

Any question?

Click edit and post your question or answer here.


Personal tools