gpt4 book ai didi

java - 数字自身相乘

转载 作者:行者123 更新时间:2023-12-01 23:45:32 25 4
gpt4 key购买 nike

我正在练习 for 循环,对于本章末尾的练习之一,它要求创建一个乘法表,显示 1 到 12 之间的整数乘以结果。这就是我所做的,产生了错误的结果。我确信我错过了一些简单的东西,但无法捕获它。

public class PP63 {

public static void main(String[] args) {

final int TOTAL = 12;


for(int i = 1; i <= TOTAL; i++)
{
for(int j = 1; j<=TOTAL; j++)
{
System.out.println(i*j);
}
}

}

}

最佳答案

基本上,您需要一个表格,而不是列表

for(int i = 1; i <= TOTAL; i++)
{
for(int j = 1; j<=TOTAL; j++)
{
System.out.print(i*j + "\t");
}
System.out.println();
}

关于java - 数字自身相乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17130133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com