打印出1-100内的所有质数
package practice1;
public class Zhishu {
public static void main(String[] args) {
for (int i = 2; i <= 100; i++) {
int j = 2;
while (i % j != 0) {
j++;
if (i == j)
System.out.println(i);
}
}
}
}
输入一个整数n,计算结果 e=1!+2!+3!+…+n!
package practice1;
import java.util.Scanner;
public class En {
public static void main(String[] args) {
System.out.println("请输入一个整数");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int e=0;
int a=1;
for(int i=1;i<=n;i++) {
a*=i;
e+=a;
}
System.out.println(e);
sc.close();
}
}