• 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
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

string formatting

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
StringBuilder s = new StringBuilder ("123456789");
S.delete (0,3) replace(1,3,"24"). Delete (4,6)
S.delete (0,3) replace(1,3,). Delete (2,5) insert (1, "24")

for S.delete (0,3) replace(1,3,"24"). Delete (4,6)
output is 4247
for S.delete (0,3) replace(1,3,). Delete (2,5) insert (1, "24")
i dont know how to work with
please any one help me how to find the result

thank you

-rahul
 
Greenhorn
Posts: 24
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, Rahul,

read linked invokations from left to right; thus you gonna get follows:

s.delete(0,3) //delete sequence of characters from index 0 to 3; second argument of the method is 1- based, not 0- based, so you've got s="456789".

s.replace(1,3, "24") //replace characters from index 1 to 3; second argument... well, same stuff as above, and you've got s="424789".

s.delete(2,5)//after this invokation you receive s="429".

s.insert(1,"24") //now s="42429"
 
rahul R khanna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Yaroslav Ashurin.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic