import java.util.Scanner;
class Multiplication{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入1-9之间的数字:");
int x = sc.nextInt();
chengFa(x);
daoChengFa(x);
}
//1.参数为int
//2.返回类型 无 因为是输出东西,所以,无返回值.
public static void chengFa(int a) {
/*九九乘法表
1*1 = 1
2*1 = 1 2*2 = 4
... ...
第i行有i个等式;
i表示行,j表示列即有j个等式,j<=i
1*i到i*j
*/
for (int i = 1;i <= a ; i++) {
for (int j = 1;j <= i ;j++ ) {
System.out.print(i + "*" + j + "=" + (i * j) + "\t");
}
System.out.print('\n');
}
}
//倒99
/*倒九九乘法表
9*1 = 9 9*2 = 18 9*3 = 27 9*4 = 36 ... 9*8 = 72 9*9 = 81
8*1 = 8 8*2 = 16 8*3 = 24 8*4 =32...8*7 = 56 8*8=64
... ...
第i行有10-i个等式
i表示行,j表示列即有j个等式,j<=10-i
(10-i)*1到(10-i)*j
*/
public static void daoChengFa(int a) {
for (int i = 1;i <= a ; i++) {
for (int j = 1;j <= a + 1 - i ;j++ ) {
System.out.print((a + 1 - i) + "*" + j + "=" + ((a + 1 - i) * j) + "\t");
}
System.out.print('\n');
}
}
}
感受:分析清楚行列,问题就会清晰很多! |
|