题目是这样的
编写程序,定义数组用来存放乘法表的结果并打印输出
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
……
1*9=9 2*9=18 …… 9*9=81
题目是这样的
编写程序,定义数组用来存放乘法表的结果并打印输出
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
……
1*9=9 2*9=18 …… 9*9=81
public class class_99 {
public static void main(String[] args) {
for(int i=1;i<=9;i++)//外面的循环是循环1-9
{
for(int u=1;u<=i;u++)// 内循环 是从1开始乘以外训的1-i的数
// 假如外循环的i=3 那么就是 1*1 1*2 1*3依次类推
{
System.out.print(u+"*"+i+"="+i*u+" ");//用不换行的输出
}
//循环完一次换行
System.out.println();
}
}
}
测试结果
public class Mul {
public static void main(String[] args) {
for (int i = 1; i <= 9; i++) { for (int n = 1; n <= i; n++) { System.out.print(n + " x " + i + " = " + i * n + " "); } System.out.println(); }
}
}
class Test1 { public static void main(String[] args) { int m=1; for(int i=1;i<=9;i++) { System.out.print((m==1?"":"\t")+i+"*"+m+"="+i*m+(m++==i?"\n":"")); if(m<=i) { i--; } else { m=1; } //m<=i?i--:m=1; } } }
//测试结果:
public static void main(String [] args){ for (int i = 1; i <= 9; i++) { for(int n = 1; n <= i; n++) { System.out.print( i + " x " + n + " = " + i * n + " "); } System.out.println(); } }
结果:
1 x 1 = 1 2 x 1 = 2 2 x 2 = 4 3 x 1 = 3 3 x 2 = 6 3 x 3 = 9 4 x 1 = 4 4 x 2 = 8 4 x 3 = 12 4 x 4 = 16 5 x 1 = 5 5 x 2 = 10 5 x 3 = 15 5 x 4 = 20 5 x 5 = 25 6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 8 x 1 = 8 8 x 2 = 16 8 x 3 = 24 8 x 4 = 32 8 x 5 = 40 8 x 6 = 48 8 x 7 = 56 8 x 8 = 64 9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81