package javaapplication27;
public class TwoDArrayDemo {
public static void main(String[] args) {
int array[][]=new int[4][]; //declaring two dimensional array
array[0]=new int[1];
array[1]=new int[2];
array[2]=new int[3];
array[3]=new int[4];
int i,j,k=0;
for(i=0;i<4;i++)
for(j=0;j<i+1;j++){
array[i][j]=k;
k++;
}
for(i=0;i<4;i++){
for(j=0;j<i+1;j++)
System.out.println(array[i][j]+ " ");
System.out.println();
}
}
}
The output of this program is:
run:
0
1
2
3
4
5
6
7
8
9
BUILD SUCCESSFUL (total time: 1 second)
0 comments:
Post a Comment