Showing posts with label Program to declare instantiate read and display the elements of 2D array in java. Show all posts
Showing posts with label Program to declare instantiate read and display the elements of 2D array in java. Show all posts

Sunday, 5 January 2020

Program to declare instantiate read and display the elements of 2D array in java

public class MyClass {
    public static void main(String args[])
    {
        int arr[][];
        arr=new int[3][3];
        for(int i=0;i<arr.length;i++)
        {
            for(int j=0;j<arr[i].length;j++)
                arr[i][j]=i;
        }
        for(int[] u: arr)
        {
            for(int ele: u)
                System.out.print(ele+" ");
            System.out.println("");
        }
    }
}