• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

substring confusion...

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Options :
A: Hell Hello
B: Hel Hel
C: Hel Hello
D: Hell Hell
Answer : c)It will print Hel Hello
I cannot understand from where did this Hello come from.
and where is 'r' in Hello??
please explain
Sonir
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its very simple
1) what does this result in
System.out.print(str.substring(0,3));

It will result in Hel since starting point is 0 and count upto 3 characters(remember the first element in indexed 1)

2)System.out.println(str.replace('r', 'h'));
after this is executed there is no match and the same string is retturned
so it is Hello refer to API for more details.
-A
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic