Twisted Prime Number


Write a Program in Java of Twisted Prime Number.

Twisted Prime Number :-

If a number is prime, and its reverse number is also prime, then it is called Twisted prime number.

For Example :- 37 is prime number , and its reverse order is 73 and 73 is also prime number.

 

import java.io.*;

public class twistprime

{

public static void main(String aa[])throws IOException

{

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

int n, r, m, i, j, g; int s=0; int k=0, c=0;

System.out.println(“Input a number”);

n=Integer.parseInt(in.readLine());

m=n;

int p=m;

while(m!=0)

{

r=m%10;

s=(s*10)+r;

m=m/10;   }

for(i=2;i<n;i++)

{

if(n%i==0)

{

k++;

}}

for(j=2;j<s;j++)

{

if(s%j==0)

{

c++;

}}

if(k==0&c==0)

{

System.out.println(p+” is twisted prime”);

}

else

{

System.out.println(p+” is not twisted prime”);

}

}

}

 output:

tw

 

Related Posts

Comments are closed.