参考代码:
import java.util.Scanner;
public class Main1139 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 2; i <= x; i++) {
if (i == 2)
System.out.print(i + " ");
for (int j = 2; j < i; j++) {
if (i % j == 0)
break;
if (j == i - 1)
System.out.print(i + " ");
}
}
}
}
0.0分
0 人评分