I see three problems so far:
You iterate
0 to k
but you cannot, because the element #k does not exist. You are trying to repeat the loop
k+1
times while you have only
k
elements. 1) Don't use such should variable names; 2) count
0 to k-1
; 3) don't do it at all; use
foreach
.
Don't use
ArrayList
; it is rendered obsolete by introduction of generics in .NET Framework v. 2.0. For new development, use
System.Collections.Generic.List
and other generic collections. Non-generic classes are bad; you will need a type cast, which is a bad thing. Please see:
http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx[
^].
Finally, I don't see where do you iterate through character of each string.
—SA