I am getting an error when converting a string to an int on line 8.
The integer parseInt method doesn't seem to be doing its job.
I have tried to use other methods to convert the string but nothing is working and its causing me to fail this coding challenge I'm doing. I have cut the rest of the code because the error in my logic is in these lines.
The error message reads
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:583)
at java.lang.Integer.parseInt(Integer.java:615)
at Solution.reverseNum(Solution.java:35)
at Solution.main(Solution.java:8)
public class Solution {
public static void main(String args[] ) throws Exception {
String sc = "1234567890123456";
int noCases = 1;
for(int i=0; i<noCases; i++){
int rev = reverseNum(sc);
} // for each credit card number
}
public static int reverseNum(String inp){ // helper function
int in =Integer.parseInt(inp);
int res = 0;
for(int i = in; i !=0; i/=10){
res = res *10 + i%10;
}
return res;
}
}