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: Str1 vs strbuf... Help please!

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

    Default Str1 vs strbuf... Help please!

    Hello

    We have been studying Strings and I don't understand the following line:
    System.out.print1n(''Length of the String is : "+str1. length());

    Shouldn't "str1" be "strbuf"?

    I have copied the code in full below. Thank you in advance for any help!
    public class StringBufferAssign {
         public static void main(String[] args) {
              StringBuffer strbuf = new StringBuffer();
              strbuf.append("Houghton Mifflin")';
     
              int len=str1.length();
              int vcount=0;
              strbuf.reverse();
              System.out.print1n("The Reverse of the string is:"strbuf);
     
              for(int i=1en=1; i>=0; i==)
              {
                 System.out.print(strbuf.charAt(i));
                 if((strbuf.charAt(i)=='a')||(strbuf.charAt(i)=='e' )
                      ||(strbuf.charAt(i)=='1')||(strbuf.charAt(i)=='o')||(strbuf.charAt(i)='u'))
                 {
                      vcount++;
                  }
               }
               System.out.print1n(''Length of the String is : "+str1. length());
     
               System.out.print1n("Number of vowels in the string is : "+ vcount):
         }   
    }
    Last edited by helloworld922; July 10th, 2013 at 10:19 PM. Reason: please use [code] tags


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Str1 vs strbuf... Help please!

    Please use [code] tags. They make it much easier to read your code, and in this case makes it quite easy to spot several simple syntax errors.

    Notably:

    strbuf.append("Houghton Mifflin")';
    There's an extra single quote.

    System.out.print1n("The Reverse of the string is:"strbuf);
    There's a missing addition operator.

    There might be others, these were the ones I could spot on first glance.

    As far as your question about strbuf vs. str1, yes. There is no declaration of str1, so it simply doesn't exist (here). You can't use something which doesn't exist. strbuf does exist, and in the context of the code it makes sense that str1 should have been strbuf.

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

    Default Re: Str1 vs strbuf... Help please!

    Thank you so much for clearing that up for me! Have a wonderful day

Tags for this Thread