d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > .length()
Add Reply New Topic New Poll
Member
Posts: 10,049
Joined: Aug 11 2014
Gold: 540.00
Oct 16 2015 10:10am
sorry about the assignment thread, I had an exam the day after and I was too lazy to take care of it but I managed in the end, thanks

small question:

lets say i input the word Hello, and I want to know if it has the letter z in this

I initiliaze int i=0, etc.

and then:

while(i<word.length())
...
...


why i<word.length and not <=??
If the word is hello, the index goes from 0 to 4 right? so it means my ''int i'' will never reach the last letter of the word?

thanks
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Oct 16 2015 05:12pm
"hello" length = 5

i = 0

0, 1, 2, 3, 4


that is all 5 letters

remember, most languages support a 0-based array
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll