I know this is probably an easy fix, but I need help on my Java homework. In it, we're supposed to find the prime, perfect, and binary palindromes of a set of numbers from zero to MAX_NUMBER. I've got the perfect and the primes down, but the binary palindromes are tripping me up. I've got it written how I think it should go, but I get an error before compiling it. The error occurs under the listPalindromes method, specifically on the "if (isPalindrome(upperBound)){" line. It is telling me 'The method isPalindrome(String) in the type PrimePerfectPalindrome is not applicable for the arguments (int).' Again, I know this is probably simple, but I haven't been able to figure it out myself. Also, if anybody knows how to get the binary representation using the modulo operation and putting it together, any help would be appreciated. Thanks for your help.
CODE
package primePerfectPalindrome;
public class PrimePerfectPalindrome {
/** Main method */
public static void main(String []args) {
//Set up the maximum number
final int MAX_NUMBER = 100;
//List all primes to MAX_NUMBER
listPrimes(MAX_NUMBER);
//List all perfects to MAX_NUMBER
listPerfects(MAX_NUMBER);
//List all binary palindromes
listPalindromes(MAX_NUMBER);
}
/** listPrimes method */
public static void listPrimes(int upperBound) {
System.out.println("2 is prime.");
for (int index = 3; index <= upperBound; index += 2){
//Test if index is prime
if (isPrime (index)){
System.out.printf(index + " is prime.\n");
}
}
}
/** isPrime method */
public static boolean isPrime(int number) {
for (int index = 2; index <= Math.sqrt(number); index ++){
if (number % index == 0){
return false;
}
}
return true;
}
/** listPerfects method */
public static void listPerfects(int upperBound) {
for (int index = 2; index < upperBound; index ++){
//Test if index is perfect
if (isPerfect(index)){
System.out.println(index + " is perfect.");
}
}
}
/**isPerfect method */
public static boolean isPerfect(int number) {
int sumOfDivisors = 1;
for (int divisor = 2; divisor < number - 1; divisor ++){
if (number % divisor == 0){
sumOfDivisors += divisor;
}
}
if (sumOfDivisors == number){
return true;
}
else{
return false;
}
}
/**listPalindromes method */
public static void listPalindromes(int upperBound) {
for (int index = 0; index <= upperBound; index ++){
if (isPalindrome(upperBound)){
System.out.println(index + " is a binary palindrome.");
}
}
}
/**isPalindrome method */
public static boolean isPalindrome(String binary) {
int low = 0;
int high = binary.length () - 1;
while (low < high) {
if (binary.charAt(low) != binary.charAt(high))
return false;
low ++;
high ++;
}
return true;
}
/**intToBinaryString method */
public static String intToBinaryString(int number) {
String binary = Integer.toBinaryString(number);
return binary;
}
}