ICSE Class 10 Computer Applications
Question 19 of 69
Iterative Constructs in Java — Question 19
Back to all questions 19
Question Question 15
Write a program that displays all the numbers from 150 to 250 that are divisible by 5 or 6, but not both.
public class KboatFactorCheck
{
public static void main(String args[]) {
for (int i = 150; i <= 250; i++) {
int mod5 = i % 5;
int mod6 = i % 6;
if ((mod5 == 0 || mod6 == 0)
&& !(mod5 == 0 && mod6 == 0)) {
System.out.println(i);
}
}
}
}Output
