Question
class output {
public static void main(String args[])
{ String s = "Hello World";
int i = s.indexOf('o');
int j = s.lastIndexOf('l');
System.out.print(i + " " + j);
}
}
What is the output of this program?
class output {
public static void main(String args[])
{ String s = "Hello World";
int i = s.indexOf('o');
int j = s.lastIndexOf('l');
System.out.print(i + " " + j);
}
}
Answer: Option C
Was this answer helpful ?
indexOf() method returns the index of first occurrence of the character where as lastIndexOf()
returns the index of last occurrence of the character.
output:
$ javac output.java
$ java output
4 9
Was this answer helpful ?
More Questions on This Topic :
Question 10.
Which of these is an oncorrect statement?
....
Submit Solution