이것은 StackOverflow에 대한 첫 번째 질문이므로 제대로하고 있지 않은지 알려주십시오. 어쨌든 상당히 철저히 검색했지만 내 문제에 대한 답을 찾지 못하는 것 같습니다. 액세스하려는 메소드는 Java (Jgrasp)에서 액세스 할 수 없습니다. 올바른 표기법을 사용하고 있다고 느끼기 때문에 이유를 잘 모르겠습니다.
//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();
}
제 질문을 읽어 주셔서 감사합니다.
안나
main 메소드 안에 최상위 코드를 넣으십시오.
public static void main(String[] args) {
PE4 tester = new PE4();
tester.NumberFinder();
}
하지만 이것은 첫 번째 단계에 불과합니다. 또한 메서드 static
에서 제거 하고 NumberFinder
실제로 회문 번호를 감지하지 않는 알고리즘을 수정해야합니다. 힌트:new StringBuilder(word).reverse().toString().equals(word)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다