0
Can u guys please help me understand the code below? Why is the output 1
public class Program { public static void main(String[] args) { String txt="please locate where 'locate' occours"; System.out.println(txt.indexOf("locate")); } }
10 Respostas
+ 2
~ swim ~ sorry what? My result was 7......
+ 2
p 0
l 1
e 2
a 3
s 4
e 5
6
l 7
o 8
c 9
a 10
t 11
e 12
....
locate occurs on index 7 the first time!
+ 1
Its definitely 7
+ 1
thanks so much,i understand now
0
When I run the programm I get the result 7. Are you sure you got 1 as output?
0
why is the result 7?
0
you are welcome
0
indexOf return 1/-1 if true then 1 if false then -1
0
The result is 7