5.10 (Find numbers divisible by 5 and 6) Write a program that displays all the numbers
from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are
separated by exactly one space.
public class ProgrammingEx5_10 { public static void main(String[] args) { int itemCount = 0; //i=0 changed to i=100 from comment below 2016.01.14 for(int i=100; i<=1000; i++){ if(i%5 == 0 && i%6 == 0){ System.out.print(i + " "); itemCount +=1; //print new line character after item 10th and reset the item count if(itemCount==10){ System.out.println("\n"); itemCount = 0; } } } } }
No comments:
Post a Comment