int arr1[];
int arr2[] = new int[10];
int arr3[] = new int[]{1,2,23,3,4,545,6};
int arr4[] = {1,2,3,344,5,56,6};
int count = 0;
for (int i = 0; i < arr2.length; i++)
{
arr2[i] = count++;
}
for (int i = 0; i < arr2.length; i++)
{
System.out.println("Array Elements: "+i);
}
for(int i:arr3)
{
System.out.println("Array Elements: "+i);
}
for (int i = 0; i < arr3.length; i++)
{
System.out.println("For Loop Array Elements: "+arr3[i]);
}
int arr1[][];
int arr2[][] = new int[3][3];
int arr3[][] = new int[][]{{1,2,3},{4,54,5},{4,3,2}};
int arr4[][] = {{1,2,3},{4,54,5},{4,3,2}};
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
System.out.print(arr3[i][j]+" ");
}
System.out.println("");
}
int arr1[][];
int arr2[][] = new int[3][3];
int arr3[][] = new int[][]{{1,2,3},{4,54,5},{4,3,2}};
int arr4[][] = {{1,2,3},{4,54,5},{4,3,2}};
int count = 0;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
arr2[i][j] = count++;
}
}
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
System.out.print(arr2[i][j]+" ");
}
System.out.println();
}
int arr1[][][];
int arr2[][][] = new int[3][3][3];
int arr3[][][] = new int[][][]{
{{1,2,3},{4,3,2},{2,5,4}},
{{1,2,3},{4,3,2},{2,5,4}},
{{1,2,3},{4,3,2},{2,5,4}}
};
int arr4[][][] = {{{1,2,3},{4,3,2},{2,5,4}},
{{1,2,3},{4,3,2},{2,5,4}},
{{1,2,3},{4,3,2},{2,5,4}}};
*/
int arr[][] = new int[3][];
arr[0] = new int[3];
arr[1] = new int[2];
arr[2] = new int[4];
int count = 0;
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[i].length; j++)
{
arr[i][j] = count++;
}
}
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[i].length; j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.