2 Dimensional Array Tutorial In Java

Published: 01 January 1970
on channel: Code Is Life
22
4

2 Dimensional Array Tutorial In Java


Source Code


class two_dim_array {
public static void main(String[] args) {
Print("Here is an example of 2D Array in Java");
// int[] nums = new int[5]; // is an example of 1D Array
int[][] nums = new int[5][5];
// putting some data into our 2D Array
nums[0][0] = 1000 * 1;
nums[0][1] = 1000 * 2;
nums[0][2] = 1000 * 3;
nums[0][3] = 1000 * 4;
nums[0][4] = 1000 * 5;

nums[1][0] = 2000 * 1;
nums[1][1] = 2000 * 2;
nums[1][2] = 2000 * 3;
nums[1][3] = 2000 * 4;
nums[1][4] = 2000 * 5;

nums[2][0] = 3000 * 1;
nums[2][1] = 3000 * 2;
nums[2][2] = 3000 * 3;
nums[2][3] = 3000 * 4;
nums[2][4] = 3000 * 5;

nums[3][0] = 4000 * 1;
nums[3][1] = 4000 * 2;
nums[3][2] = 4000 * 3;
nums[3][3] = 4000 * 4;
nums[3][4] = 4000 * 5;

nums[4][0] = 5000 * 1;
nums[4][1] = 5000 * 2;
nums[4][2] = 5000 * 3;
nums[4][3] = 5000 * 4;
nums[4][4] = 5000 * 5;

// now printing theme

for (int i = 0; i nums.length; i++) {
for (int k = 0; k nums[i].length; k++) {
Print("nums[" + i + "]" + "[" + k + "] = " + nums[i][k]);
Print("\n");
}
Print("\n");
}
}

public static void Print(Object _object_) {
System.out.print(_object_);
}
}


On this page of the site you can watch the video online 2 Dimensional Array Tutorial In Java with a duration of hours minute second in good quality, which was uploaded by the user Code Is Life 01 January 1970, share the link with friends and acquaintances, this video has already been watched 22 times on youtube and it was liked by 4 viewers. Enjoy your viewing!