public static void main(String[] args) {
int a = 1;
int i = 1;
while (a <= 2000)
{
if (0 == a%3 && 0 == a%8)
{
System.out.print(a + " ");
if (0 == i% 10)
{
System.out.println("");
}
i++;
}
a++;
}
运行结果:
public class Test {
public static void main(String[] args) {
int count = 1;
for (int i = 1; i <=2000; i++) {
if (i%3==0 && i%8==0) {
System.out.print(i+" ");
if (count++%10==0)
System.out.println();
}
}
}
}