java code keeps throwing exception -
my code throws exception java.lang.string.charat
@ line in code :
while(0 == chartoint(value.charat(startvalueat))){
in code segment,
private static arraylist<integer> stringtoarray(string value){ arraylist<integer> holder = new arraylist<integer>(); int startvalueat = 0; if(value.charat(0)=='-'|| value.charat(0)=='+') startvalueat= 1; else startvalueat = 0; while(0 == chartoint(value.charat(startvalueat))){ startvalueat++; } int startofvalue = value.length() - (startvalueat - 1); //to make sure arraylist right size , last element ends @ 0 find starting index of j above step //we use value of startvalueat for(int = startofvalue, j = startvalueat; j <= value.length() - 1; i--, j++){ holder.add(0, chartoint(value.charat(j))); } return holder; }
here stack trace:
exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: 4 @ java.lang.string.charat(string.java:686) @ bigint.stringtoarray(bigint.java:145) @ bigint.<init>(bigint.java:35) @ bigint.multiplybysingledigit(bigint.java:853) @ bigint.multiplypositives(bigint.java:878) @ bigint.multiplyonenegative(bigint.java:920) @ bigint.multiply(bigint.java:778) @ bigint_add_sub_mul_div_mod_demo.main(bigint_add_sub_mul_div_mod_demo.java:164)
while(startvalueat < value.length() && 0 == chartoint(value.charat(startvalueat))){ startvalueat++; }
you ignoring case string
0
s. call value.charat(value.length())
throws exception.
Comments
Post a Comment