0
guys I have a question in array. When i run the code it prints "sanji" since the statement is [2] & it is count as 0,1,2. now ++
if I print the example statement (inside the comment) it will print (3) right? so why did the output is 3 and not 2? or length doesn't read 0's instead it reads 1,2 and so on? Thanks in advance :) https://code.sololearn.com/ciHHoQa88Gj0/?ref=app
2 Antworten
+ 1
Length means elements present in array. So whenever you count no of elements counting will start from 1 itself.
And index always start from 0 length and index both are different things. For example ..
In mathematics whole numbers were start from 0 but natural numbers are starts from 1 similarly in case of array as well.
This is my explanation or answer. If wrong then kindly correct me
+ 3
String [] anime = { "zoro", "luffy", "sanji" };
anime[ 0 ] = "zoro"
anime[ 1 ] = "luffy"
anime[ 2 ] = "sanji"
There are 3 elements, and index of the elements goes from 0 ~ 2