While Stephen M Irving's answer is pretty spot on and corrects all the beliefs found in your question, this still answers your question, trying to minimize the number of statements.
public class CoolDude {
public static void main(String[] args) {
for (int i = 100; i <= 500; i++)
if (i % 5 == 0 || i % 11 == 0) // This is the condition where we decide to print something
System.out.printf("%s%s- %d%n", i % 5 == 0 ? "Cool " : "", i % 11 == 0 ? "Dude " : "", i);
}
}
However, this code duplicates one of the most expensive part: the modulo. Also, this solution is not readable !
When trying to figure solutions is useful to try several KPI and then find the best to optimize. In this case, you wanted to optimize the number of lines, it's definitely not the best as you can see above. If anything try first to get a working solution then a readable one and finally an optimized one where you document why it's optimized so that the readability is maintained.
Here, for instance, is the most optimized version I could come up with. It definitely contains more lines, but also is definitely faster, since I skip all invalid numbers and never do a modulo (only two divisions and two multiplications for the whole program).
public class CoolDude {
public static void main(String[] args) {
final int min = 100;
final int max = 500;
for (int i5 = nextMultiple(min, 5), i11 = nextMultiple(min, 11); i5 <= max || i11 <= max; ) {
if (i5 < i11) {
System.out.printf("Cool - %d%n", i5);
i5 += 5;
} else if (i11 < i5) {
System.out.printf("Dude - %d%n", i11);
i11 += 11;
} else { // i5 == i11
System.out.printf("Cool Dude - %d%n", i5);
i5 += 5;
i11 += 11;
}
}
}
static int nextMultiple(int number, int divisor) {
int roundToLower = (number - 1) / divisor * divisor;
return roundToLower + divisor;
}
}