Translate

Monday 25 August 2014

Double dimensional array in java

Double Dimensional Array in java is used to store data in tabular format. To access an individual element of DDA we require 2 indexes:- Row index and Element index.

Declaring DDA variable:-
int arr[ ][ ];
int [ ]arr[ ];
int [ ][ ]arr;


Defining DDA variable:-
arr = new int[4][3];  // here 4 is no of row and 3 is no of column
arr.length = no of row
arr[i].length = no of column


Initialising DDA:-
int arr[ ][ ] = {{90, 80, 70},{40, 50,60},{30, 20, 10}};


Assigning DDA:-
for(i=0; i<arr.length; i++)
    for(j=0; j<arr[i].length; j++)
        arr[i][j] = 100;

No comments:

Post a Comment

Total Pageviews