-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwistedPrimeNumber.java
More file actions
47 lines (43 loc) · 854 Bytes
/
Copy pathTwistedPrimeNumber.java
File metadata and controls
47 lines (43 loc) · 854 Bytes
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
import java.util.Scanner;
public class TwistedPrimeNumber
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int no=sc.nextInt();
isTwistedPrimeNo(no);
}
public static void isTwistedPrimeNo(int no){
if (isPrimeNo(no)) {
int n=reverseNo(no);
if (isPrimeNo(n))
System.out.println(no+" and "+n+" are a Twisted Prime Number");
else
System.out.println(no+" is a Prime Number but not Twisted Prime");
}
else
System.out.println(no+" is not a Prime Number");
}
public static boolean isPrimeNo(int no)
{
for (int i=2;i<=no/2 ;i++ )
{
if (no%i==0)
{
return false;
}
}
return true;
}
public static int reverseNo(int no)
{
int rev=0;
for (int j=no;j!=0 ;j=j/10 )
{
int last=j%10;
rev=rev*10+last;
}
return rev;
}
}