输入一串数字求各位数之和
import java.util.Scanner;
public class File33 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
/*
int a,b=0;
while(( a =sc.nextInt())!=0){
b+=a;
}
System.out.println(b);
*/
System.out.println(“其请输入一个大于等于二的数”);
int a = sc.nextInt();
System.out.println(“请输入一个比上一个更大的数”);
int b = sc.nextInt();
int i, c = 0;
for (i = a; i <= b; i++) {
boolean s = antr(i);
if (s || i == 2) {
c++;
System.out.print(i + " ");
}
if (c == 0) {
System.out.println(“两数差距太小,或是错误,无法生成数据”);
}
}
}
public static boolean antr(int i) {
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0)
return false;
}
return true;
}
}