/*
(Palindromic prime) A palindromic prime is a prime number and also palindromic.
For example, 131 is a prime and also a palindromic prime, as are 313 and
757. Write a program that displays the first 100 palindromic prime numbers. Display
10 numbers per line, separated by exactly one space, as follows:
2 3 5 7 11 101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
...
*/
package Calismalarim;
public class palindromic_Primes {
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 count = 0;
int PrimeNumbers = 1;
while (PrimeNumbers <= 100) {
if (isPalindrome(number) && isPrime(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;
}
}