-
Notifications
You must be signed in to change notification settings - Fork 331
/
prime_palindrome.java
69 lines (64 loc) · 1.36 KB
/
prime_palindrome.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.*;
class prime_palindrome
{
void showPrimePal()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter m");
int m=sc.nextInt();
System.out.println("Enter n");
int n=sc.nextInt();
int c=0;
if(m>n ||n>3000)
{
System.out.println("out of range");
}
else
{
System.out.println(" prime palindrome integers are");
while(m<=n)
{
if(PrimePal(m)==true)
{
if(c==0)
System.out.print(m);
else
System.out.print(","+m);
c++;
}
m++;
}
System.out.println("\nfrequency of prime palindrome integer="+c);
}
}
boolean PrimePal(int x)
{
boolean flag= false;
int c=0,rev=0,d=0,cp=0;
cp=x;
for(int i=1;i<=x;i++)
{
if(x%i==0)
{
c++;
}
}
if(c==2)
{
while(x>0)
{
d=x%10;
rev=rev*10+d;
x=x/10;
}
if(rev==cp)
flag=true;
}
return flag;
}
public void main()
{
prime_palindrome obj = new prime_palindrome();
obj.showPrimePal();
}
}