java打印乘法表

1

int a1 = 1;
		int b1 = 1;
		int c1 = 1;
		while (a1 <= 9) {
			while (b1 <= a1) {
				c1 = a1 * b1;
				System.out.print(b1 + "X" + a1 + "=" + c1 + "\t");
				b1++;
			}
			System.out.println();
			a1++;
			b1 = 1;
		}

 

2

for (int k = 1; k <= 9; k++)
			System.out.printf("%5d", k);
		for (int i = 1; i <= 9; i++) {
			System.out.println();
			System.out.printf("%-4d", i);
			for (int j = 1; j <= i; j++)
				System.out.printf("%-5d", i * j);
		}

 

3

int x, y;
		for (x = 0; x <= 9; x++) {
			for (y = 1; y <= x; y++) {
				System.out.print(y + "X" + x + "=" + x * y + "\t");
			}
			System.out.println();
		}

 

4

 

int i, j, k;
		for (i = 9; i >= 1; i--) {
			for (j = 1; j <= i; j++) {
				k = i * j;
				System.out.print(j + "*" + i + "=" + k + "\t");
			}
			System.out.println();

		}

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

返回顶部