Java Table Code with Multi-Dimensional Array
In the code below, two-dimensional array is used to construct a code for a table of number 10.
In the code loop inside the loop and a ++ early value increment operator is used.
First a two-dimensional array is initialized with two square brackets. Now in the loops, first the initialized variable values of i and j are checked according to the conditions defined in the middle portion of the loop and then the control goes to next statement System.out.println(); and after that to the ++operator which increases the values of the variable by 1. The loop terminates when the condition defined returns boolean value false.
In the loop .length method returns the length of array.
public class myTableClass {
public static void main(String[] args) {
int[][] myNumbers = { {1, 2, 3, 4,5,6,7},{8,9,10}};
for (int i = 0; i < myNumbers.length; ++i) {
for(int j = 0; j < myNumbers[i].length; ++j) {
System.out.println(“10 * “ + myNumbers[i][j] + “ = “ + 10 * myNumbers[i][j]);
}
}
}
}
After compiling the above code, following out put shows on to console
10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
10 * 4 = 40
10 * 5 = 50
10 * 6 = 60
10 * 7 = 70
10 * 8 = 80
10 * 9 = 90
10 * 10 = 100
Keep coding and visit below for more learning
https://www.roseindia.net/java/index.shtml #table #coding