Last active
August 29, 2015 14:19
-
-
Save jonathan-irvin/b060951be3820e62a5c8 to your computer and use it in GitHub Desktop.
Emirp Finder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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