Skip to content

Instantly share code, notes, and snippets.

@jonathan-irvin
Last active August 29, 2015 14:19
Show Gist options
  • Save jonathan-irvin/b060951be3820e62a5c8 to your computer and use it in GitHub Desktop.
Save jonathan-irvin/b060951be3820e62a5c8 to your computer and use it in GitHub Desktop.
Emirp Finder
public class Emirp {
public static boolean isPrime(int number){
for (int divisor = 2;divisor < number;divisor++){
if(number % divisor == 0){
return false;
}
}
return true;
}
public static int reverse(int number){
int reversedNumber = 0;
int temp = 0;
while(number > 0){
//use modulus operator to strip off the last digit
temp = number%10;
//create the reversed number
reversedNumber = reversedNumber * 10 + temp;
number = number/10;
}
return reversedNumber;
}
public static boolean isPalindrome(int number){
if(number == reverse(number)){
return true;
}else{
return false;
}
}
public static void main(String[] args) {
for (int number = 2; number < 1000; number++){
if (isPrime(number)){
int reversedNumber = reverse(number);
if (isPrime(reversedNumber)==true){
if(isPalindrome(number)==false){
System.out.println(number);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment