gpt4 book ai didi

java - 我怎样才能让这个程序打印出每行十个项目,中间用 1 个空格分隔?

转载 作者:行者123 更新时间:2023-12-01 12:27:05 27 4
gpt4 key购买 nike

这是我到目前为止的代码

public class DivisibleBy5and6
{
public static void main (String []args)
{
for (int i = 100; i <= 200; i++)
{
boolean num = (i % 5 == 0 || i % 6 == 0) && !(i % 5 == 0 && i % 6 == 0);

if (num == true)
System.out.println(i + " is divisible");
}
}
}

如前所述,如何让输出打印出每行 10 个项目,并用空格分隔?

最佳答案

怎么样:

int count = 0;
for (int i = 100; i <= 200; i++) {
boolean num = (i % 5 == 0 || i % 6 == 0) && !(i % 5 == 0 && i % 6 == 0);

if (num == true) {
count++;
System.out.print(i + " is divisible ");
if(count >= 10) {
System.out.println();
count -= 10;
}
}
}

关于java - 我怎样才能让这个程序打印出每行十个项目,中间用 1 个空格分隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26246071/

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