I'm trying to print out all odd numbers that aren't multiples of 7 or 9. It works by seeing if the remainder is first not 0 when divided by two, giving the odd numbers.
But when I've put it to show the numbers if they are not multiples of 7 it just displays ALL the odd numbers, have I made a mistake?
public class NoMultiples7and9 {
public static void main(String[] args) {
for (int i = 1; i <= 30; i++) {
if (i % 2 != 0) {
if (i % 7 != 0 || i % 9 != 0) {
System.out.println(i);
}
}
}
}
}
i % 7 !=0 || i % 9 != 0evaluate ifiis a multiple of only 7 (e.g. 21)? What should it evaluate to? Get that working correctly and the rest should fall out.