• 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

replace method

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class TestWipro
{
public static void replaceJ(String[] text)
{
text.replace ("j", "l");
}
public static void main(String args[])
{
String text = new String ("java")
replaceJ(text);
System.out.println(text);
}
}

hi all,
can anybody provide the output with explanation for the above program?


thanks,
venkat
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compile errors - missing semicolon in main, passing a string to a method that expects a string array, calling a method replace on a string array when this method is defined in string, passing strings to this method when char expected.

If u fix these and pass a string to the replaceJ method and instead of ""'s in call to replace(char, char) use ''s then the output is java as you havent assigned the string returned from replace method to anything so its instantly lost

//Tom
 
reply
    Bookmark Topic Watch Topic
  • New Topic