Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: String help please!

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default String help please!

    I've been going through the StringBuffer part of my unit and believe that I have gained enough understanding to manipulate the StringBuffer in a program. Yet each time I try to invoke one of the methods outlined in the unit, I'm given an error message. Is there something wrong with my syntax or logic? Is there something that I need to import? Any help would be appreciated. I am attaching my output below. Thank you all so much!

    public class StringBuffer
    {
    public static void main(String[] args)
    {
    StringBuffer sbuff = new StringBuffer();

    //one attempt to append - error
    sbuff.append("Jenna");

    //second attempt to append - error
    String phrase = new String("Jenna");
    sbuff.append(phrase);

    //attempts to call upon other methods - errors
    System.out.println("Your name backwards is: " + sbuff.reverse());
    System.out.println("The length of your name is: " + sbuff.length());
    }
    }
    Attached Images Attached Images


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: String help please!

    I'm given an error message
    Please copy the full text of the error message and paste it here. It has important info about the error.

    On windows: To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Location
    Aarhus, Denmark
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Take a look at the name of your own class, and then tell me what you think will happen when you call, new StringBuffer. How does Java know which one you mean?

    Rolf

Similar Threads

  1. Replies: 2
    Last Post: March 28th, 2013, 09:54 AM
  2. Replies: 3
    Last Post: October 26th, 2012, 02:19 PM
  3. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  4. [SOLVED] difference between String Concatenation and String -Buffer/Builder .append(<value>)
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 3rd, 2011, 08:16 AM
  5. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM