Monday 26 October 2015

Java Tutorial : Java Array (Multidimensional Array)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=LiBK0ZZljt0&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Array (Multidimensional Array) 
ArrayDemo.java
class ArrayDemo
{
    public static void main(String[] args)
    {
        int[][] intArray = new int[2][3];

        intArray[0][0] = 10;
        intArray[0][1] = 20;
        intArray[0][2] = 30;

        intArray[1][0] = 100;
        intArray[1][1] = 200;
        intArray[1][2] = 300;

        System.out.println("Element at intArray[0][0] : " + intArray[0][0]);
        System.out.println("Element at intArray[0][1] : " + intArray[0][1]);
        System.out.println("Element at intArray[0][2] : " + intArray[0][2]);

        System.out.println();

        System.out.println("Element at intArray[1][0] : " + intArray[1][0]);
        System.out.println("Element at intArray[1][1] : " + intArray[1][1]);
        System.out.println("Element at intArray[1][2] : " + intArray[1][2]);

    }
}
Output
Element at intArray[0][0] : 10
Element at intArray[0][1] : 20
Element at intArray[0][2] : 30

Element at intArray[1][0] : 100
Element at intArray[1][1] : 200
Element at intArray[1][2] : 300
ArrayLoopDemo.java
public class ArrayLoopDemo
{

    public static void main(String[] args)
    {
        int[][] intArray = new int[2][3];

        intArray[0][0] = 10;
        intArray[0][1] = 20;
        intArray[0][2] = 30;

        intArray[1][0] = 100;
        intArray[1][1] = 200;
        intArray[1][2] = 300;

        int rows = intArray.length;

        System.out.println("Number of rows : " + rows+"\n");
        
        for (int i = 0; i < rows; i++)
        {
            int columns = intArray[i].length;
            
            System.out.println("Number of columns in row "+ i +" is : " + columns);
            
            for (int j = 0; j < columns; j++)
            {
                System.out.println("Element at " + "intArray[" + i + "]" + "["
                        + j + "] : " + intArray[i][j]);

            }
            System.out.println();
        }

    }

}
Output
Number of rows : 2

Number of columns in row 0 is : 3
Element at intArray[0][0] : 10
Element at intArray[0][1] : 20
Element at intArray[0][2] : 30

Number of columns in row 1 is : 3
Element at intArray[1][0] : 100
Element at intArray[1][1] : 200
Element at intArray[1][2] : 300
To Download ArrayDemoMultiDimensionalApp Project Click the below link
https://sites.google.com/site/javaee4321/java/ArrayDemoMultiDimensionalApp.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment