Within 100 to 300 is neither output is divisible by 3 5 not be divisible.

Ideas:

1 through all the numbers between 100 and 300

2. Locate not divisible by 3 5 can not divisible, i.e. 3 modulo this number is not equal to 0, is not equal to 0 modulo 5

Code:

public class Demo1 {
	public static void main(String[] args) {
		for (int i = 100; i < 300; i++) {
			if ((i % 3 != 0) && (i % 5 != 0)) {
				System.out.println(i);
			}
		}
	}
}

operation result:

Published 28 original articles · won praise 5 · Views 5799

Guess you like

Origin blog.csdn.net/weixin_41879980/article/details/95855901