write a program in Java to accept a no. N check if it is a twisted prime no. Or not
Answers
Answered by
4
Here we go,
import java.io.
*;public class twistedprime{ public static void main(String args[])
throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n, r, m, i, j, g, s=0, k=0, c=0; System.out.println("Input a number"); n=Integer.parseInt(br.readLine());
m=n; int p=m;
while(m!=0) { r=m%10; s=(s*10)+r; m=m/10; } for(i=1;i<=n;i++)
{ if(n%i==0) { k++; } } for(j=1;j<=s;j++) { if(s%j==0) { c++; } } if(k==2&c==2) { System.out.println(p+" is twisted prime"); } else { System.out.println(p+" is not twisted prime"); } }}
Similar questions
Business Studies,
6 months ago
Science,
6 months ago
India Languages,
6 months ago
History,
1 year ago