• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

String Method

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was wondering if someone could help me fix my code so that when something like createAcronym("As Soon As Possible") is tested it would work properly. I guess it has to do with the return?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no point using System.out.println() method if you return an empty string. You could either make the method void and print the characters one by one:



and call it like:



OR (Which iseems the right way for me)


and call it like:



and don't forget to close Scanner resource in the end:


 
Hanna Roberts
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well the reason I have the return type is because that is what it wants me to use so I can't do your first way. Im not sure I can use that builder thing in my code though. I dont believe I've learned it yet. What does it do?
 
Robert Ilin
Greenhorn
Posts: 15
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java String objects are immutable. That basically means that you can't change the content of a String object.  Everytime you call methods that "modift" String content, the program actually creates a new object and assigns it to the object you are trying to modify. String builder is a faster alternative when you need to create String objects by appending characters one by one since it doesn't create a new object everytime. But if you say you can't use StringBuilder I suggest you this approach:

 
Hanna Roberts
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh ok thank you for the explanation and thanks that way worked
 
reply
    Bookmark Topic Watch Topic
  • New Topic