Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class CircularPrime
- {
- public static void main()
- {
- Scanner sc = new Scanner(System.in);
- int n,num=0,number,c=0,count=0,temp,first;
- String s = "",ss;
- int i,d;
- System.out.println("enter a number");
- n = sc.nextInt();
- int temp1 = n;
- do
- {
- for(i = 1;i<=n;i++)
- {
- if(n%i==0)
- c++;
- }
- if(c!=2)
- {
- count=0;
- break;
- }
- else
- {
- first = n;
- temp = n;
- while(first >= 10)
- {
- first = first/ 10;
- }
- ss = Integer.toString(temp);
- int l = ss.length();
- for(i = 1;i<l;i++)
- {
- d = temp%10;
- s = d+s;
- temp = temp/10;
- }
- try
- {
- num = Integer.parseInt(s+first);
- }
- catch(NumberFormatException ex)
- {
- System.out.println("not a number");
- }
- if(temp1!=num)
- {
- System.out.println(num);
- }
- n = num;
- s = "";
- temp=0;
- ss="";
- count = c;
- c = 0;
- }
- }while(temp1!=num);
- if(count==2)
- System.out.println("number is circular prime");
- else
- System.out.println("number is not circular prime");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement