这是我到目前为止的代码
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/