Okay, so I'm almost done with this program, but I need it to display all the palindromes from 100 to "user input" AND all prime palindromes from that list. So far I can only get it to display all the prime palindromes.
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Please enter a number greater than 100: ");
int userInput = input.nextInt();
if(userInput <= 100)
{
System.out.print("That number is not big enough, please enter a "
+ "number greater than 100");
}
else
{
System.out.println("The Prime Palindrome Integer between 101"
+ " and " + userInput + " are: ");
}
for (int i = 101; i <= userInput; i++)
{
Integer userInt = new Integer(i);
String userString = userInt.toString();
char[] userChar = userString.toCharArray();
if (isPrime(i) && arraysAreEqual(userChar, reverseArray(userChar)))
{
printArray(userChar);
System.out.print(", ");
}
}
}
public static char[] reverseArray(char[] list)
{
String reverse = new StringBuilder(new String(list)).reverse().toString();
char[] revArray = reverse.toCharArray();
return revArray;
}
public static boolean arraysAreEqual(char[] list1, char[] list2)
{
if (Arrays.equals(list1, list2) )
return true;
else return false;
}
public static boolean isPrime(int intPrime)
{
for (int i = 2; i < Math.sqrt(intPrime); i++)
{
if (intPrime % i == 0)
return false;
}
return true;
}
public static void printArray(char[] list)
{
for (int i = 0; i < list.length ; i++)
{
System.out.print(list[i]);
}
}
}