java - Printing numbers divisible by 2 but not 3? -


for (int i=n1; < n2; i++){     if (i % 2 == 0){         system.out.println(i);     } } 

this code prints out numbers between n1 , n2 (which generated randomly) both divisible 2 , 3, want print out numbers divisible 2. how do this?

you're literally halfway there.

you need second condition in mandate number not divisible 3. this:

!(i % 3 == 0) 

now, need boolean operator return true if both conditions true. that, i'll leave exercise reader.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -