이것은 구형 온라인 판사 palin problem의 해결책입니다. 그것은 Netbeans에서 잘 실행되지만 판사는 RuntimeError를주는 답을 거부합니다. JCreator에서 시도해 보았습니다.왜이 프로그램은 jcreator에서 런타임 오류를 제공하지만 netbeans에서는 그렇지 못합니까?
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.parseInt(Integer.java:497)
at Main.main(Main.java:73)
구문 분석을 위해 빈 문자열을 전달하지 않습니다. 이유가 무엇입니까?
코드 :
import java.io.*;
import java.util.*;
class Main {
public static int firstPalinLargerThanNum(int num){
int foundPalin =0;
int evalThisNum = ++num;
while (true){
if (isPalin(evalThisNum))
break;
evalThisNum++;
}
foundPalin = evalThisNum;
return foundPalin;
}
public static boolean isPalin(int evalThisNum){
boolean isItPalin = false;
int dig=0;
int rev=0;
int n = evalThisNum;
while (evalThisNum > 0)
{
dig = evalThisNum % 10;
rev = rev * 10 + dig;
evalThisNum = evalThisNum/10;
}
if (n == rev) {
isItPalin=true;
}
return isItPalin;
}
public static void main(String args[]) throws java.lang.Exception{
BufferedReader r1 = new BufferedReader(new InputStreamReader(System.in));
/*BufferedReader r1 = new BufferedReader (new FileReader(new File ("C:\\Documents and Settings\\Administrator\\My Documents\\NetBeansProjects\\Sphere\\src\\sphere\\sphere\\PALIN_INPUT.txt")));*/
String read = r1.readLine();
int numberOfTestCases = Integer.parseInt(read);
for (int i=0; i<numberOfTestCases;i++){
read = r1.readLine();
if (read!=null){
int num = Integer.parseInt(read);
System.out.println(firstPalinLargerThanNum(num));
}
}
}
}
입력 : 73입니다
2
808
2133
라인 : 프로그램이 숫자를 기대 할 때 <Enter>
을 치면 int num = Integer.parseInt(read);
입력 내용은 무엇입니까? 그리고 73 행은 무엇입니까? –
입력이 링크에 있으면, 여기에 명확한 설명을 위해 게시하겠습니다. – andandandand