java - How to define a starting point in the condition? -


the problem:

i want numbers 1-50 not divisible 7, don't have 7 in them, 17,27,etc. code below works (i-10)%7 has start i=6. thinks number 3 doesn't count cause (3-10)=-7 0 mod 7. how solve in if statement?

for(int i=1; i<=50;i++){     if(i%7!=0 &&  (i-10)%7!=0){         system.out.println(i); 

your second condition wrong. 27 ends in 7, (27-10)%7!=0.

you need check % 10 not 7.

if(i%7!=0 && i%10!=7) 

Comments