程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

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();

		}