I'm trying to write a code that finds the multiples of 3 and 5 in an array of numbers 1 to 100, the code I have generates the numbers I want but it gives me the multiples of 3, then gives me the multiples of 5 (Example: 3 6 9 12 15,5 10 15) I want them all together (Example 3 5 6 9 10 12 15).
here is the code I have so far
for(int i = 0 ; i < 100; i=i+3){
if(i%3 == 0)
System.out.println(i);
}
for (int i=1; i < 100; i++) {
if (i%5==0) System.out.println(i);}
I also tried
if(i%3 == 0 && i%5==0)
but that only gave me the numbers divisible by both
an explanation after would be helpful thank you