- (구글링 했음)
import java.util.*;
public class palindrome {
public static void main(String[] args) {
System.out.println("Enter a number : ");
Scanner input = new Scanner(System.in);
int num=input.nextInt();
int newnum=reverse(num);
isPalindrome(newnum);
}
public static int reverse(int number) {
int reverse=0;
while(number!=0) {
int digit=number%10;
reverse=reverse*10+digit;
number/=10;
}
return reverse;
}
public static boolean isPalindrome(int number) {
boolean isPalindrome=true;
if(number==reverse(number)) {
System.out.println("It is a palindrome.");
isPalindrome=true;
}
else {
System.out.println("It is not a palindrome.");
isPalindrome=false;
}
return isPalindrome;
}
}
- (구글링 했음)
import java.util.*;
public class emirp {
public static void main(String[] args) {
final int NUMBER_OF_EMIRPS=120;
final int NUMBER_OF_PRIMES_PER_LINE=10;
int count=0;
int number=2;
while(count<NUMBER_OF_EMIRPS) {
if(isPrime(number)&&isPrime(palindrome.reverse(number))&&number!=palindrome.reverse(number)) {
count++;
System.out.print(number+" ");
if(count%10==0) {
System.out.println();
}
}
number++;
}
}
public static boolean isPrime(int number) {
for(int divisor=2;divisor<=number/2;divisor++) {
if(number%divisor==0) {
return false;
}
}
return true;
}
}