forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplicationTable.java
More file actions
36 lines (32 loc) · 906 Bytes
/
MultiplicationTable.java
File metadata and controls
36 lines (32 loc) · 906 Bytes
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
import java.util.Formatter;
public class MultiplicationTable
{
public static void table(int max)
{
System.out.print("\t"); //Header numbers
for (int start = 1; start <= max; start++)
{
System.out.print("\t" + start); // Header numbers
}
System.out.println();
System.out.print("\t "); // header lines
for (int start = 1; start <= max; start++)
{
System.out.print("-----"); // header lines
}
System.out.println();
for (int outer = 1; outer <= max; outer++)
{
System.out.print(outer + "\t" + " | ");
for (int inner = 1; inner <= max; inner++)
{
System.out.print("\t" + outer * inner);
}
System.out.println();
}
}
public static void main(String[] args)
{
table(20);
}
}