/*
(Emirp) An emirp (prime spelled backward) is a nonpalindromic prime number
whose reversal is also a prime. For example, 17 is a prime and 71 is a prime, so 17
and 71 are emirps. Write a program that displays the first 100 emirps. Display 10
numbers per line, separated by exactly one space, as follows:
13 17 31 37 71 73 79 97 107 113
149 157 167 179 199 311 337 347 359 389
...
*/
package Calismalarim;
public class emirpPrimes {
public static void main(String[] args) {
final byte Number_of_primes = 100;
final byte Number_of_per_line = 10;
long starttime=System.currentTimeMillis();
int number = 2;
int PrimeNumbers = 0;
while (PrimeNumbers <= Number_of_primes) {
if (isPrime(reverse(number)) && isPrime(number)&& !isPalindrome(number)) {
PrimeNumbers++;
if (PrimeNumbers % Number_of_per_line == 0)
System.out.println(number);
else
System.out.print(number + " ");
}
number++;
}
long endtime=System.currentTimeMillis();
System.out.println("gecen süre "+(endtime-starttime)+" milis");
}
public static int reverse(int number) {
String rev = "";
while (number != 0) {
int revN = number % 10;
rev = rev + revN;
number = number / 10;
}
return Integer.parseInt(rev);
}
public static boolean isPalindrome(int number) {
if (reverse(number) == number)
return true;
else
return false;
}
public static boolean isPrime(int number) {
boolean isPrime = true;
for (int i = 2; i <= number / 2; i++) {
if (number % i == 0) {
isPrime = false;
break;
} else
isPrime = true;
}
return isPrime;
}
}