-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathCountPrime.java
41 lines (41 loc) · 867 Bytes
/
CountPrime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Count number of prime digit in a Number
* Input : 254786135
* Output : 5
*/
import java.util.*;
public class CountPrime {
public static void main(String[] args)
{
int count=0;
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
for (int i = 0; i < s.length(); i++)
{
int p = Integer.parseInt(String.valueOf(s.charAt(i)));
if(isPrime(p)==true)
{
count++;
}
}
System.out.println(count);
}
public static boolean isPrime(int n)
{
int c=0;
for (int i = 2; i < n; i++)
{
if(n%i==0)
{
c++;
}
}
if(c==0 && n>1)
{
return true;
}
else
{
return false;
}
}
}