gpt4 book ai didi

java - 我需要创建一个 10x10 乘法表,但我不断收到错误

转载 作者:行者123 更新时间:2023-12-02 04:20:34 33 4
gpt4 key购买 nike

我需要创建一个 10x10 乘法表。现在我有了这个,但它有一些我想修复的错误。

      public static void main(String[] args) {
int n=10;
int i=1;
int j=1;
while (i <= n)
j=1;
while ( j <=n)
printf(" %3d", i * j);
j=j+1;
System.out.println();
i=i+1;
}

最佳答案

好吧,对于初学者来说,java 中不存在单独的 printf() 。其次,需要使用括号来包含循环。试试这个代码:

public static void main(String[] args) {
for (int i =1; i <= 10; i++){
//cycles through the first number to multiply

for (int b=1; b <=10; b++){
//cycles through second number to multiply
System.out.print(i*b + " ");
}
System.out.println();
}
}

这段代码对我有用,我希望它对你也有用!

关于java - 我需要创建一个 10x10 乘法表,但我不断收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32815123/

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