• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in program of String Handling- please review

 
vijay kumar dahiya
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void main(String[] args) {
String s="vijay kumar";
System.out.println(s);
System.out.println(s.lastIndexOf('k');
System.out.println(s.lastIndexOf('k',4));
System.out.println(s.lastIndexOf('k',9));
}

ouput is:
s.lastIndexOf('k') is: 6
s.lastIndexOf('k',4) is: -1
s.lastIndexOf('k',9) is: 6

please write me how it print is:
s.lastIndexOf('k',4) is: -1
s.lastIndexOf('k',9) is: 6

thanks.
 
Henry Wong
author
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s.lastIndexOf('k',4) is: -1


If you start at index position 4, and search backwards for the 'k', where would you find it? Or will you find it?

s.lastIndexOf('k',9) is: 6


If you start at index position 9, and search backwards for the 'k', where would you find it?

Henry
 
vijay kumar dahiya
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you Mr. Henry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic