• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in program of String Handling- please review

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks you Mr. Henry.
 
reply
    Bookmark Topic Watch Topic
  • New Topic