+ 3

How the answer is 4?

String greeting="Sololearn"; System.out.print(greeting.indexOf("Solo")); System.out.print(greeting.indexOf("Learn"));

28th Apr 2017, 5:50 AM
Hasrat Wadsariya
Hasrat Wadsariya - avatar
3 odpowiedzi
+ 4
when the character is not found in the given string its returns -1. here 'L' is not there in sololearn so it returns -1. is output : 0-1
28th Apr 2017, 8:55 AM
Manideep
Manideep - avatar
+ 3
Answer is "04" Method indexOf(String str) returns the index within this string of the first occurrence of the specified substring. I think there is a mistake in the task, author meant String greeting =" SoloLearn"
28th Apr 2017, 6:10 AM
Alexey
Alexey - avatar
+ 2
the answer is not 4, the answer is "0-1"
28th Apr 2017, 6:10 AM
Anik Shandhi
Anik Shandhi - avatar