I wanted to see what the smallest number divisible by all one digit numbers was and instead of looking it up I created this.
public static void main(String[] args) {
for (int i = 100; i < 10000; i++) {
if (i % 2 ==0) {
if (i % 3 ==0) {
if (i % 4 ==0) {
if (i % 5 ==0) {
if (i % 6 ==0) {
if (i % 7 ==0) {
if (i % 8 ==0) {
if (i % 9 ==0) {
System.out.println(i);
break;
}
}
}
}
}
}
}
}
}
}
As you can see, I have an if statement in an if statement x9. The code worked but I wanted to condense my if statements using an array to make my if statement like this but it didn't work.
if (i % x[1, 2, 3, 4, 5, 6, 7, 8]) {
System.out.println(i);
break;
}
Any suggestions?