Write a program that displays all the numbers from 100 to 20
Write a program that displays all the numbers from 100 to 200, ten per line, that are divisible by 5 or 6, but not both. Numbers are separated by exactly one space.
Solution
NumbersPrint.java
public class NumbersPrint {
public static void main(String[] args) {
int count = 1;
for(int i=100; i<=200; i++){
if(!(i % 5 == 0 && i % 6 == 0)){
if(i % 5 == 0 || i % 6 == 0){
count++;
System.out.print(i+\" \");
if(count % 11 == 0){
System.out.println();
}
}
}
}
}
}
Output:
100 102 105 108 110 114 115 125 126 130
132 135 138 140 144 145 155 156 160 162 165
168 170 174 175 185 186 190 192 195 198 200
