计算0至某个范围内(小于2147483647)的素数

import java.util.Scanner;

public class PrimeNumber{
	public static void main(String[] args){
		System.out.println("请输入范围");
		Scanner a = new Scanner(System.in);
		int b = a.nextInt();
		a.close();
		System.out.println(2);
		int c[] = new int[b + 1];
		for (int i = 3; i <= b; i += 2)
			c[i] = i;
		for (int i = 3; i <= b; i += 2)
			for (int j = 3; j <= i; j += 2)
				if (i * j <= b)
					c[i * j] = 0;
				else
					break;
		for (int i = 3; i <= b; i += 2)
			if (c[i] != 0)
				System.out.println(c[i]);
	}
}

你可能感兴趣的:(Java)