参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for(int i = 2; i <= n; i++) if(judge(i)) System.out.println(i); } public static boolean judge(int x) { for(int i = 2; i * i <= x; i++) if(x % i == 0) return false; return true; } }
0.0分
6 人评分