This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in program of String Handling- please review

 
vijay kumar dahiya
Ranch Hand
Posts: 33
  • 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: 21399
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks you Mr. Henry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic