This is my first question on StackOverflow so please tell me if I'm not doing it right. Anyway, I've searched fairly thoroughly but can't seem to find an answer to my problem. The method I want to access won't be accessed on Java (Jgrasp). I'm not sure why since I feel like I'm using the right notation.
//PROJECT EULER Problem #4
//A palindromic number reads the same both ways. The largest palindrome made
//from the product of two 2-digit numbers is 9009 = 91 × 99.
//Find the largest palindrome made from the product of two 3-digit numbers.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PE4
{
public boolean isPalindrome(int five)
{
String word = Integer.toString(five);
if (word.length()==5 &&word.substring(0,2).equals(word.substring(3,5)))
return true;
else if(word.length()==6 &&word.substring(0,3).equals(word.substring(3,6)))
return true;
else
return false;
}
public static void NumberFinder()
{
for (int i=999; i>599; i--)
{
for (int j=999; j>i-300; j--)
{
if (isPalindrome(i*j)==true)
{
System.out.print(i + ", " + j + " = " + i*j);
break outerloop;
}
}
}
return 0;
}
PE4 tester = new PE4();
tester.NumberFinder();
}
Thanks for taking the time to read my question.
Anna
Put your top-level code inside the main method:
public static void main(String[] args) {
PE4 tester = new PE4();
tester.NumberFinder();
}
This is just the first step, though. You must also remove static
from the NumberFinder
method and fix your algorithm, which doesn't actually detect palindromic numbers. Hint: new StringBuilder(word).reverse().toString().equals(word)