Computer Science, asked by sreemoyeesen26, 1 month ago

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 amrapalidas1967
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