java - why's this program giving a runtime error on jcreator but not on netbeans? -
This is my solution for the online judge of the area. It is running fine on Netbeans, but the judge rejecting my answer Is that it gives a runtime error. I tried it on JCreator and it says:
Exception in thread "main" java.lang.NumberFormatException: for input string: "java.lang.NumberFormatException.forInputString (NumberFormatException. Java: 48) at java.lang.Integer.parseInt (integer.javascuite68) at java.lang.Integer.parseInt (Integer. Java: 497) Main. Main (Maine Java: 73)
> I am not passing an empty string to parse, why is this?
Code:
import java.io. *; Import java.util. *; Class main {public static intelglobalTatan (int no) {intestrol = 0; Int evalThisNum = ++ num; While (true) {if (ezellin (virene nnn) break); EvalThisNum ++; } FoundPalin = evalThisNum; Returned Publicin; } Public static boolean ezelline (int oculum henum) {boolean estalin = falls; 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 is Estelin; } Public static zero main throws java.lang.Exception {string alge []) {BufferedReader r1 = new BufferedReader (New InputStreamReader (System.in)); / * BufferedReader r1 = New BufferedReader (New FileReader (new file ("C: \\ Documents and Settings \\ Administrator \\ My Documents \ NetBens Project \\ Area \\ src \ \ sphere \\ sphere \ PALIN_INPUT.txt" ))); * Read / String = r1.readLine (); Int number of test case = integer. Persian (reading); For (int i = 0; i
Input:
2 808 2133
line is 73: int num = Integer.centre (read);
If you have & lt; Enter & gt;
When the program is expecting a number
Assume that your input is
2 <3> Enter & gt;
You will be prompted after processing with error 3, just as you have asked twice to repeat it again.
On one hand, handling around the number parsing at the top of the error, you may apply the trim ()
to readLine ()
method calls Want to:
read the string = R1.readLine (). Trim ();
This can allow you to handle this event satisfactorily, that the user should be placed around the blank space.
Comments
Post a Comment