• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

get the length of the string

 
johny Sill
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How to get length of the string with out using string length method,

Help me,

Thanks in advance
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"johny beginer",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted, often without warning

thanks,
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to give us a good reason not to use the length method, that's what it is for.
 
Fahd Shariff
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print it, cut it out, weigh it.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
Print it, cut it out, weigh it.


Thats how my chemistry professors used to calculate the area under a curve back when they were undergrads. Gotta love the old - skool.
[ July 28, 2006: Message edited by: Garrett Rowe ]
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can be done in one method call without using length() and without printing anything out. Look at the documentation and check out detailed documentation for each method that returns an int. There's at least one in particular that will return an index equal to this.length(). Other's could easily return something that will not be a String but will easily tell you the length of the original String.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My dad gave me that, and I got credit in HS science calculating the area of an irregular shape. It's right up there with ways to determine the height of a building using a barometer.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
My dad gave me that, and I got credit in HS science calculating the area of an irregular shape. It's right up there with ways to determine the height of a building using a barometer.


From this parible/ article:
  • Take a barometer to the top of the building, attach a long rope to it, lower the barometer to the street and then bring it up, measuring the length of the rope. The length of the rope is the height of the building.
  • Take the barometer to the top of the building and lean over the edge of the roof. Drop that barometer, timing its fall with a stopwatch. Then using the formula S = �at�, calculate the height of the building.
  • ...take the barometer out on a sunny day and measure the height of the barometer and the length of its shadow, and the length of the shadow of the building and by the use of a simple proportion, determine the height of the building.
  • ...take the barometer and begin to walk up the stairs. As you climb the stairs, you mark off the length of the barometer along the wall. You then count the number of marks, and this will give you the height of the building in barometer units. A very direct method.
  • ...tie the barometer to the end of a string, swing it as a pendulum, and determine the value of 'g' at the street level and at the top of the building. From the difference of the two values of `g' the height of the building can be calculated.
  • take the barometer to the basement and knock on the superintendent's door. When the superintendent answers, you speak to him as follows: "Mr. Superintendent, here I have a fine barometer. If you tell me the height of this building, I will give you this barometer."
  •  
    Jim Yingst
    Wanderer
    Sheriff
    Posts: 18671
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    [GR]: Take a barometer to the top of the building, attach a long rope to it, lower the barometer to the street and then bring it up, measuring the length of the rope. The length of the rope is the height of the building.

    Yeah, that barometer is really irreplaceable in this case. That role couldn't possibly be filled by al large rock. Or a small rock. Or... hell, no rock or anything else at all. I think ropes have enough weight of their own to hand in a generally downward direction.

    [GR]: ...take the barometer and begin to walk up the stairs. As you climb the stairs, you mark off the length of the barometer along the wall. You then count the number of marks, and this will give you the height of the building in barometer units. A very direct method.

    Yep. I assume you meant the veritical length, as the length along the general direction of the staircase is irrelevant. You can also do this more directlly by having someone scale the building, if the edifice is suitably craggy for footholds. If you're not moving straight up (or down) - are you drawing a really precise horizontal line every time you need to delimit two different barometer height measurements? Probably not. Seems like this will be a rather large source of errors for this method.

    [GR]: ...tie the barometer to the end of a string, swing it as a pendulum, and determine the value of 'g' at the street level and at the top of the building. From the difference of the two values of `g' the height of the building can be calculated.

    the funny thing about this answer is that it overlooks that it's achieved a better answer about halfway through, before anyone has to travel up (or down) the length of the building. (Easy in an elevator, but pretty tiring if you have to use the staircase.) I'm thinking that the variation in g is a very poor way to determine building height, considering that local variations in density (e.g.. mountains) are likely to be much more significant than differences in distance from the center of the earth is. Feh. Maybe this is different for those of you in flat areas of the Earth, but for me: forget about the difference between 'g' values at the bottom and top of the building - just use a standard value for g-at-anywhere-roughly-on-the-surface-of-the-earth, plus the period of the pendulum (at top or bottom; doesn't really matter), and plug into the pendulum equation to determine the length of the pendulum. Assuming the earlier just-measure-the-length-of-the-damn-rope technique has failed for some reason - don't want to overlook the even-more-obvious solution.

    [GR]: take the barometer to the basement and knock on the superintendent's door. When the superintendent answers, you speak to him as follows: "Mr. Superintendent, here I have a fine barometer. If you tell me the height of this building, I will give you this barometer."

    While this is my favorite answer to this particular chestnut, I have to think that there's a significant possibility the super has no idea what the height of the building is, but is perfectly willing to lie on the spot in order to obtain that fine barometer. (Tremendously valuable, no doubt.) Trust no one.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic