Java語言程式設計(基礎篇)第十版 5.10-11
阿新 • • 發佈:2018-12-14
public class j5_10 { public static void main(String[] args) { // TODO Auto-generated method stub int counter = 0; for(int i = 100;i<=1000;i++) { if(i %5 == 0 && i %6 == 0) { System.out.printf("%4d",i); counter ++; } if(counter %10==0 && counter >1) { System.out.printf("\n"); counter = 0; } } } }
public class J5_11 { public static void main(String[] args) { // TODO Auto-generated method stub int counter = 0; for(int i = 100;i<=200;i++) { if(i %5 == 0 && i %6 == 0) { continue; } else if(i % 5 ==0 || i % 6 ==0) { System.out.printf("%4d",i); counter ++; } if(counter %10==0 && counter >1) { System.out.printf("\n"); counter = 0; } } } }