// 3.求解1到100之间的偶数
public static void Test3() {
System.out.println("1到100之间的偶数为:");
for (int i = 0; i <= 100; i++) {
if (i % 2 == 0) {
System.out.print(i + " ");
}
}
}
这样看着不是不方便,稍微改动下,每行少输出几个数字,多输出几行
// 3.求解1到100之间的偶数(输入是,每行输出9个数字)
public static void Test3_3() {
int count = 0;
System.out.println("1到100之间的偶数为:");
for (int i = 0; i <= 100; i++) {
if (i % 2 == 0) {
System.out.print(i + " ");
count++;
if (count == 9) {
System.out.print("
----------------------------------------
");
count = 0;
}
}
}
}