Circular_prime.java

Pls check this code maam
mail@pastecode.io avatar
unknown
java
a year ago
1.2 kB
3
Indexable
import java.util.Scanner;

public class circular_prime {
    private static int isPrime(int num)
    {
        int i;
        for(i = 2; i < num; i++)
        {
            if(num % i == 0)
            {
                return(0);
            }
        }
        return(1);
    }
    private static int digit_counter(int n)
    {
        int count = 0;
        while( n > 0)
        {
            count++;
            n /= 10;
        }
        return(count);
    }
    public static void main(String[] args){
        int n,r,res,digits,count = 0,prime = 0, comp = 0;
        Scanner read_ip = new Scanner(System.in);
        n = read_ip.nextInt();
        digits = digit_counter(n);
        res = n;
        do
        {
            r = res % 10;
            res = r * (int)Math.pow(10,digits-1) + (res / 10);
            if (isPrime(res) == 1) {
                prime++;
            }
            else
            {
                comp++;
            }
        }while(res != n);
    
    if((comp > 0 && prime > 0)||(comp > 0))
    {
        System.out.println("Not Circular Prime");
    }
    else if(prime > 0)
    {
        System.out.println("Circular Prime");
    }
}
}