import java.sql.SQLOutput;
import java.util.Scanner;
public class HomeWork {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = 2;
int num = scan.nextInt();
if (num == 1) {
System.out.println(num + "是素数!");
} else {
while (i <= Math.sqrt(num)) {
if (num % i == 0) {
System.out.println(num + "不是素数");
return;
}
i++;
}System.out.println(num + "是素数~");
}
}
}
2、打印 1 - 100 之间所有的素数
public static void main(String[] args) {
//打印 1 - 100 之间所有的素数
Scanner scan = new Scanner(System.in);
int max = scan.nextInt();
int num = 1;
while (num <= max) {
int i = 2;
boolean del = true;
while (i <= Math.sqrt(num)) {
if (num % i == 0) {
del = false;
break;
}
i++;
}
if (del) {
System.out.println(num);
}
num++;
}
}
3、输出 1000 - 2000 之间所有的闰年
public static void main(String[] args) {
//输出 1000 - 2000 之间所有的闰年
int y = 1000;
while(y<=2000){
if ((y%100!=0&&y%4==0)||y%400==0){
System.out.println(y);
}
y++;
}
}
4、编写程序数一下 1到 100 的所有整数中出现多少个数字9
public static void main(String[] args) {
//编写程序数一下 1到 100 的所有整数中出现多少个数字9
int n = 1;
int count =0;
while(n<=100){
if(n%10==9){
count++;
}
if(n/10==9&&n%10!=9){
count++;
}
n++;
}
System.out.println(count);
}
}