Results 1 to 3 of 3
  1. #1
    woodmandan2 is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Lightbulb Java Strings and StringsBuffer Help?!

    Hi All,

    Firstly I'd like to thank you for even considering looking at my code. This is my first post on this forum and hopefully there is somebody out there who can help me!

    Anyways, the jist of it is that I am working on an online programming class and attempting to create a program to satisfy the conditions specified below:

    The goal is to write two programs, one using the String class and the other one using the StringBuffer class. Your programs need to store a set of Strings in an ArrayList and then it should print those Strings in the order by which they are added. The program requirements also include an output consisting of a complete sentence.

    I have attempted both programs, and starting from a total of over 20 errors I have them down to failing to compile with one error each. I am rather lost on what exactly I did wrong, and what to do next. Any information on what the next step would be to take would be fantastic. Again, keep in mind that I am a beginner, and please excuse the possibility of a horrendous mistake or simple fix.
    Thanks!

    Dan

    Java Strings Program

    Java Code:
    import java.util.ArrayList;
    public class string
    {
    	public static void main(String[] args)
    	{
    		String n1 = "I";
    		String n2 = "enjoy";
    		String n3 = "eating";
    		String n4 = "fried";
    		String n5 = "chicken";
    		String n6 = "on";
    		String n7 = "Fridays!";
    		ArrayList sentence = new ArrayList ();
    		sentence.add (0, n1);
    		sentence.add (1, n2);
    		sentence.add (2, n3);
    		sentence.add (3, n4);
    		sentence.add (4, n5);
    		sentence.add (5, n6);
    		sentence.add (6, n7);
    		System.out.print(sentence.get (0));
    		System.out.print(sentence.get (1));
    		System.out.print(sentence.get (2));
    		System.out.print(sentence.get (3));
    		System.out.print(sentence.get (4));
    		System.out.print(sentence.get (5));
    		System.out.print(sentence.get (6));
    	}
    }
    StringBuffer Program

    Java Code:
    public class StringBuffer
    {
    	public static void main(String[] args)
    	{
    		
    		String Buffer sentence = new StringBuffer();
    		sentence.append ("I");
    		sentence.append("Enjoy");
    		sentence.append("eating");
    		sentence.append("fried");
    		sentence.append("chicken");
    		sentence.append("on");
    		sentence.append("Fridays!");
    		System.out.println(sentence);
    	}
    }

  2. #2
    woodmandan2 is offline Member
    Join Date
    Jan 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java Strings and StringsBuffer Help?!

    Java Strings and StringsBuffer Help?!-javaissue.png

    I screenshotted both compiler errors in the last photo, with StringBuffers first and Strings second.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Strings and StringsBuffer Help?!

    The error tells you exactly what is wrong and on what line. Please read the line carefully:

    Java Code:
    String Buffer sentence = new StringBuffer();
    Notice any difference between String Buffer and StringBuffer?

    Also, you can easily copy and paste text from a cmd window, so please post the text from the window rather than a screen shot since some of us can't get images due to firewalls.

Similar Threads

  1. Want to validate Strings in java gui
    By juxta in forum New To Java
    Replies: 8
    Last Post: 05-07-2012, 01:24 AM
  2. Formatting Strings in Java
    By ladykrimson in forum New To Java
    Replies: 3
    Last Post: 11-03-2010, 09:31 AM
  3. Drawing strings in Java
    By LyraM in forum Java 2D
    Replies: 4
    Last Post: 05-12-2010, 12:15 AM
  4. The java Strings
    By greenteachacha in forum Jobs Discussion
    Replies: 8
    Last Post: 04-16-2009, 06:08 AM
  5. Sorting strings in java?
    By alexander.s in forum New To Java
    Replies: 10
    Last Post: 09-01-2008, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •