输出100以内能被7整除的前5个数
(1)while循环
public class DemoA{
public static void main(String[] args) {
int count = 0;
int i = 1;
//while循环实现
while(i <= 100) {
if(i%7 == 0) {
System.out.println(i);
count++;
}
i++;
//提前终止循环
if(count == 5) {
break;
}
}
}
}
(2)for循环实现
public class DemoB {
public static void main(String[] args) {
int count2 = 0;
for(int i1 = 1;i1<=100;i1++) {
if(i1 % 7 == 0) {
System.out.println(i1);
count2++;
}
if(count2 == 5) {
break;
}
}
}
}