-6

(C#)

ScreenShots: https://pasteboard.co/JGKU92J.jpg https://pasteboard.co/JGKUrQd.jpg

I wrote in first one < and the other one <=
Why when I wrote <= like that it gaveme error? Sorry for my Englsih

Code: https://www.paste.org/113948

sako007
  • 3
  • 1
  • 2
    1) include code ***in your question*** - as ***text***. 2) error - ***what error***? 3) read [how to ask](https://stackoverflow.com/help/how-to-ask) 4) because we start counting at 0. so an array (or string) with 3 elements has the elements 0, 1 and 2. _no_ element 3. – Franz Gleichmann Dec 26 '20 at 20:19
  • Does this answer your question? [What is an "index out of range" exception, and how do I fix it?](https://stackoverflow.com/questions/24812679/what-is-an-index-out-of-range-exception-and-how-do-i-fix-it) –  Dec 26 '20 at 20:25

1 Answers1

0

Don't forget 0 when counting the entries of a list. When you are asking for the length of a List, Array, String,... the program gives you back the amount of values that are in there. But you cannot check position metin[metin.length()] as it will never be defined, because metin[0] is already a position.

The last position of your array is metin[metin.length()-1], but when you are doing the for loop until i is greater or equal than metin.length() you are asking for one more, which is undefined and hence the error.