Computer Science, asked by sherlock29, 7 months ago

Write a program to input any 10 integers in one dimensional array then find the sum of all prime numbers only and print. . Example : If input : 25,11,36,3,55,23,26,94,40,7 Output : sum=11+3+23+7=44 Write a java program for this question.

Answers

Answered by hoangmustang
11

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;

}

}

Explanation:

PLEASE MARK ME BRAINLIEST OR THANKS

Answered by emoji9585
2

Answer:

import java.util.*;

class PrimeSum

{

public static void main(String args[])

{

int i,j,n,s=0,c;

Scanner sc=new Scanner(System.in);

System.out.println(“Enter 10 integers:”);

for(i=1;i<=10;i++)

{

n=sc.nextInt();

c=0;

for(j=1;j<=n;j++)

{

if(n%j==0)

c++;

}

if(c==2)

s=s+n;

}

System.out.println(“Sum of prime numbers=”+s);

}

Similar questions