sum of prime numbers in a digit in java

Solutions on MaxInterview for sum of prime numbers in a digit in java by the best coders in the world

showing results for - "sum of prime numbers in a digit in java"
Leonardo
08 Apr 2018
1import java.util.*;
2public class PrimeDigit
3{
4    public boolean IsPrime(int i)
5    {
6        boolean b=true;
7        int d=2;
8        while(d<i/2)
9        {
10            if (i%d==0)
11            {
12                b=false;
13                break;
14            }
15            d++;
16        }
17        return b;
18    }
19    public static void main(String []args)
20    {
21       Scanner sc=new Scanner(System.in);
22       System.out.print("Enter A Number : ");
23       int i=sc.nextInt();
24       int s=0,r;
25       PrimeDigit pd=new PrimeDigit();
26       while(i>0)
27       {
28            r=i%10;
29            if(pd.IsPrime(r))
30			{
31                s = s + r;
32			}
33            i = i / 10;
34       }
35       System.out.print("Sum Of The Prime Digits : " + s );
36    }
37}
38