-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiDimMultiplicationTable.java
63 lines (48 loc) · 1.62 KB
/
MultiDimMultiplicationTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* Desired Output:
Multiplication Table
1 2 3 4 5 6 7 8 9
— — — — — — — — — — — — — — — —— — — — — — — — — — — — —
1 | 1 2 3 4 5 6 7 8 9
2 | 2 4 6 8 10 12 14 16 18
3 | 3 6 9 12 15 18 21 24 27
4 | 4 8 12 16 20 24 28 32 36
5 | 5 10 15 20 25 30 35 40 45
6 | 6 12 18 24 30 36 42 48 54
7 | 7 14 21 28 35 42 49 56 63
8 | 8 16 24 32 40 48 56 64 72
9 | 9 18 27 36 45 54 63 72 81
*/
public class MultiDimMultiplicationTable {
public static void main(String[] args) {
int[][] intArray = new int[10][10];
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
intArray[i][j] = i*j;
}
}
System.out.println("Multiplication Table");
System.out.print(" ");
for (int j = 1; j <= 9; j++)
System.out.print(" " + j);
System.out.println("\n — — — — — — — — — — — — — — — —— — — — — — — — — — — — —");
for (int i = 1; i <= 9; i++) {
System.out.print(i + " | ");
for (int j = 1; j <= 9; j++) {
System.out.printf("%4d" , intArray[i][j]);
}
System.out.println();
}
}
}
/* Alignment:
printf("%4d\n", 1);
printf("%4d\n", 12);
printf("%4d\n", 123);
printf("%4d\n", 1234);
Will give you:
___1
__12
_123
1234
(with spaces instead of underscores)
*/