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

Python Kivy ListView: How to delete selected ListItemButton? -

asp.net mvc 4 - A specified Include path is not valid. The EntityType '' does not declare a navigation property with the name '' -