• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Assignment 1b (Hundred)

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to capture the length of the first arguement in the program. So, I've been trying to get this via the StringBuffer class. My syntax is wrong....can someone correct the code below:
Public StringBuffer(args[0]);
int theLen = StringBuffer.length(args[0]);
Thanks in advance,
Mike
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the String class's length() method.

[This message has been edited by Marilyn deQueiroz (edited May 01, 2001).]
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike
I've done nothing with StringBuffer yet
The way I did it was to set a string equal to arg[0] and then I got the length of the string.
s.length()
Good luck
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do what Marilyn and Johannes said, but if to ease your mind about your code, But the problem is that you capitalized the "P" in public. Also, you cannot declare a StringBuffer like you do a String. For a StringBuffer you have to use the new keyword. Should be:

But again, for this assignment, I would use a String instead of a StringBuffer.
Bill
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using the recommended text check out the "The Length of an Entire Arry Versus a String in an Array" topic on page 111. If I understand your question I think that will shed some light on the issue. If you're like me you probably started out with using a specific index on the array and if you don't pass a parameter you'll get an array index out of bounds exception.
I've not submitted 1b (waiting on nitpicks for 1a) but the stuff I cited above proved very useful. If you don't have the text check out the API for Java. The Array class has a data field called length.
Good luck.
 
Mike Cunningham
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wanted to say thanks to the Sheriff, Ranch Hand, Bartender and fellow greenhorn for the reply's. I'll get back on my horse and try out those suggestions.
- Mike
 
That's a very big dog. I think I want to go home now and hug this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic