# Circular Prime Program in Java

## A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its digits will be prime. For example, 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime.

```
import java.util.Scanner;
public class CircularPrime
{
public static void main(String[] args)
{
boolean flag = true;
int n, num, r, c = 0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
r = num % 10;
c++;
num = num / 10;
}
num = n;
for (int i = 1; i <= c; i++)
{
r = num % 10;
num = num / 10;
num = (r * (int) Math.pow(10, c - 1)) + num;
if (!prime(num))
{
flag = false;
break;
}
}
if(flag)
{
System.out.println("Circular Prime");
}
else
{
System.out.println("Not Circular Prime");
}
}
static boolean prime(int n)
{
// TODO code application logic here
int i = 2;
boolean flag = true;
while (n > i)
{
if (n % 2 == 0)
{
flag = false;
break;
}
i++;
}
return flag;
}
}
```

#### Output:

Enter number=137 Circular Primeb. tech. bca icse java java tutorials learn java mca programs

### Frequently Asked Questions

##### What is Circular Prime?

A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its digits will be prime. For example, 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime.

##### What is Circular Prime in Java?

A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its digits will be prime. For example, 1193 is a circular prime, since 1931, 9311 and 3119 all are also prime.

**Recent Posts**

- Prefix increment/decrement Program in C April 11, 2021
- Understand the floating point arithmetic operations Program in C April 11, 2021
- Integer arithmetic operations Program in C April 4, 2021
- Find out the size and limits of data types Program in C April 4, 2021
- ICSE - Computer Applications - for Class 10 - 2019 Solved January 4, 2021
- Selection Sort in String Program in Java January 4, 2021
- Amicable Numbers Program in Java December 24, 2020
- Java Constructors October 1, 2020
- Java String Function replace() July 26, 2020
- Java String Function length() July 26, 2020
- Java String Function lastIndexOf() July 26, 2020
- Java String Function join() July 26, 2020
- Java String Function isEmpty() July 26, 2020
- Java String Function intern() July 26, 2020
- Java String Function getChars() July 26, 2020
- Java String Function getBytes() July 26, 2020
- Java String Function format() July 26, 2020
- Java String function equalsIgnoreCase() July 25, 2020
- Java String Function equals() July 25, 2020
- Java String function contains() July 25, 2020