九九乘法表
package resume.com;
public class ChengFaBiao {
//第一种
public void fan1() {
int result = 1;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
result = i * j;
if (j < i) {
System.out.print(i + "*" + j + " = " + result + " ");
} else {
System.out.println(i + "*" + j + " = " + result + " ");
}
}
}
}
//第二种
public void fan2() {
int i, j;
int[][] a = new int[10][10];
for (i = 1; i <= 9; i++) {
for (j = 1; j <= i; j++) {
a[i][j] = i * j;
System.out.print(i + "*" + j + "=" + a[i][j] + " ");
}
System.out.println(" ");
}
}
//第三种
public void fan3() {
outer: for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j > i) {
System.out.println(" ");
continue outer;
}
System.out.print(" " + i + "*" + j + "=" + (i * j));
}
}
}
//第四种
public void fan4() {
int a[][] = new int[10][10];
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
a[i - 1][j - 1] = i * j;
}
}
for (int m = 0; m < a.length - 1; m++) {
for (int n = 0; n <= m; n++) {
if (n == m) {
System.out.println(" " + a[m][n]);
} else {
System.out.print(" " + a[m][n]);
}
}
}
}
//第五种
public void fan5() {
int a = 0, b = 0, c = 0;
for (int i = 0; i < 9; i++) {
a = i + 1;
for (int j = 0; j < i + 1; j++) {
b = j + 1;
c = a * b;
System.out.print(a + "*" + b + "=" + c + " ");
}
System.out.println(" ");
}
}
//第六种
public void fan6() {
int i = 1, k;
do {
k = 1;
do {
System.out.print(i + "*" + k + "=" + (i * k) + "\t");
k++;
} while (k <= 9);
System.out.println();
i++;
} while (i <= 9);
}
//第七种
public void fan7() {
int i = 1, j = 1;
while (i <= 9) {
while (j <= 9) {
System.out.print(i + "*" + j + "=" + (i * j) + "\t");
j++;
}
System.out.println();
i++;
j = 1;
}
}
//第八种
public void fan8() {
for (int i = 1; i <= 9; i++) {
for (int k = 1; k <= 9; k++) {
System.out.print(i + "*" + k + "=" + (i * k) + "\t");
}
System.out.println();
}
}
public static void main(String[] args) {
ChengFaBiao cfb = new ChengFaBiao();
cfb.fan1();
System.out.println();
cfb.fan2();
System.out.println();
cfb.fan3();
System.out.println();
cfb.fan4();
System.out.println();
cfb.fan5();
System.out.println();
cfb.fan6();
System.out.println();
cfb.fan7();
System.out.println();
cfb.fan8();
}
}
这是输出结果:
1*1 = 1
2*1 = 2 2*2 = 4
3*1 = 3 3*2 = 6 3*3 = 9
4*1 = 4 4*2 = 8 4*3 = 12 4*4 = 16
5*1 = 5 5*2 = 10 5*3 = 15 5*4 = 20 5*5 = 25
6*1 = 6 6*2 = 12 6*3 = 18 6*4 = 24 6*5 = 30 6*6 = 36
7*1 = 7 7*2 = 14 7*3 = 21 7*4 = 28 7*5 = 35 7*6 = 42 7*7 = 49
8*1 = 8 8*2 = 16 8*3 = 24 8*4 = 32 8*5 = 40 8*6 = 48 8*7 = 56 8*8 = 64
9*1 = 9 9*2 = 18 9*3 = 27 9*4 = 36 9*5 = 45 9*6 = 54 9*7 = 63 9*8 = 72 9*9 = 81
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
0*0=0
1*0=0 1*1=1
2*0=0 2*1=2 2*2=4
3*0=0 3*1=3 3*2=6 3*3=9
4*0=0 4*1=4 4*2=8 4*3=12 4*4=16
5*0=0 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*0=0 6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*0=0 7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*0=0 8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*0=0 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27
4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27
4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9
2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18
3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27
4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81