forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSevenG.java
More file actions
62 lines (54 loc) · 1.44 KB
/
SevenG.java
File metadata and controls
62 lines (54 loc) · 1.44 KB
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
import java.sql.SQLOutput;
public class SevenG
{
public static void main(String[] args)
{
multTable(5);
System.out.println();
multTable(125);
}
private static void multTable(int max)
{
int outerCount = 1;
int innerCount;
int headerCount = 1;
int spaceCount = 0;
String header = "";
String spacer = "";
String inLine = "";
while (headerCount <= max)
{
header += ("\t\t|\t\t" + headerCount);
headerCount++;
}
while (spaceCount < header.length())
{
if (header.charAt(spaceCount) == '\t')
spacer += "----";
spaceCount++;
}
System.out.println(header + "\t\t|");
System.out.println(spacer);
while (outerCount <= max)
{
System.out.print(outerCount + "\t\t|\t\t");
innerCount = 1;
while (innerCount <= max)
{
if ((innerCount * outerCount) > 999)
{
inLine += ((innerCount * outerCount) + "\t|\t\t");
}
else
{
inLine += ((innerCount * outerCount) + "\t\t|\t\t");
}
innerCount++;
}
System.out.print(inLine);
inLine = "";
System.out.println();
outerCount++;
}
}
}