write a function sumprime(int) to input a number and display the digits which are prime. also print the sum of the prime digits
Answers
Answered by
1
Answer:
public class SumPrime
{
public void sumprime(int n)
{
int sum=0,count=0;
int temp=n;
while(temp!=0)
{
int d=temp%10;
for(int i=0;i<=d;i++)
{
if(d%i==0)
{
count++;
}
}
if(count==2)
{
System.out.println(d+ " is a prime Number");
sum+=d;
}
temp/=10;
}
System.out.println("Sum of prime = "+sum);
}
}
Similar questions
Chemistry,
21 days ago
Math,
21 days ago
Math,
21 days ago
Sociology,
1 month ago
Biology,
1 month ago
Computer Science,
9 months ago
Accountancy,
9 months ago