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