求100到200的质数

package test920;

public class PrimeNumberTest {
	public static void main(String[] args) {
		int d = 0;
		for (int i = 100; i <= 200; i++) {
			boolean f = true;
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					f = false;
					break;
				}
			}

			if (!f) {
				continue;
			}

			if (f) {
				++d;
			}

			System.out.print(i + "\t");
			if (d % 10 == 0) {
				System.out.println();

			}
		}
	}
}

结果:

101 103 107 109 113 127 131 137 139 149

151 157 163 167 173 179 181 191 193 197

199 211 223 227 229 233 239 241 251 257

263 269 271 277 281 283 293

猜你喜欢

转载自blog.csdn.net/rocling/article/details/82795569