-4
在這段代碼中用戶輸入我想增加或僅質數之和其中的所有質或不是質數組合,但元素的第n個號...將第n個元素接受到數組中並將所有進入數組的素數相加?
public class prime {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
System.out.println("enter the size of an array");
int abc = in.nextInt();
int num[] = new int[abc];
int a = 0, sum = 0;
for (int k = 0; k < num.length; k++) {
System.out.println("enter the value" + (k + 1));
num[k] = in.nextInt();
}
for (int i = 0; i < num.length - 1; i++) {
for (int j = 2; j < i; j++) {
if (num[i] % i == 0) {
a = 1;
break;
}
}
if (a == 0) {
sum = sum + i;
}
}
System.out.println("number is prime" + sum);
}
}