输出1-100内前5个能被3整除的数
时间:2020-02-19 18:57:45
收藏:0
阅读:56
public class BeDivided { public void m1(){ int count = 0; for(int i=1;i<=100&&count<5;i++){ if(i%3 == 0){ count++; System.out.print(i+" "); } } } public void m2(){ int count = 0; int i = 1; while(i <= 100){ if(i%3 == 0){ count++; System.out.print(i+" "); } if(count == 5){ break; } i++; } } public static void main(String[] args){ BeDivided b = new BeDivided(); b.m1(); System.out.println(); b.m2(); } }
原文:https://www.cnblogs.com/yxfyg/p/12332368.html
评论(0)