Initialize multidimensional arrays

Enclose each dimension's initializer within its own set of curly braces.


public class Main{ 
  public static void main(String args[]) { 
    double m[][] = { 
            { 0, 1, 2, 3 }, 
            { 0, 1, 2, 3 }, 
            { 0, 1, 2, 3 }, 
            { 0, 1, 2, 3 } 
        }; 
    for(int i=0; i<4; i++) { 
      for(int j=0; j<4; j++){ 
        System.out.print(m[i][j] + " "); 
      }
      System.out.println(); 
    } 
  } 
}

When you run this program, you will get the following output:


0.0 1.0 2.0 3.0 
0.0 1.0 2.0 3.0 
0.0 1.0 2.0 3.0 
0.0 1.0 2.0 3.0 
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.