我的任务是制作一个从 1 到 10 的乘法表,但我对我的代码不满意,它似乎很长:
for (int i = 1; i <= 10; i++)
{
System.out.println("1x" + i + " = " + i + "\t" + "2x" + i + " = " + (2*i)
+ "\t" + "3x" + i + " = " + (3*i) + "\t" + "4x" + i + " = " + (4*i)
+ "\t" + "5x" + i + " = " + (5*i) + "\t" + "6x" + i + " = " + (6*i)
+ "\t" + "7x" + i + " = " + (7*i) + "\t" + "8x" + i + " = " + (8*i)
+ "\t" + "9x" + i + " = " + (9*i) + "\t" + "10x" + i + " = " + (10*i));
}
输出:
1x1 = 1 2x1 = 2
1x2 = 2 2x2 = 4
etc.