wap in java to input 10 integers and find the average of the prime numbers ony.
Answers
Answered by
1
Answer:
CHECK OUT MY SOLUTION: package newPack;
import java.util.*;
public class sumPrime {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] a = new int[10];
int sum = 0;
for(int i = 0; i < a.length; i++) {
int y = input.nextInt();
if(isPrime(y)==true)
sum+=y;
}
System.out.println(sum);
}public static boolean isPrime(int e) {// method check whether the number is prime or not
boolean right = true;
for(int i = 2; i <= e/2; i++) {
if(e%i==0) {
right = false;
}
}
return right;
}
}
Please mark me as brainleast
Similar questions