• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assignment Java-4b (Say)

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe I've got my design down for the solution to this program, but my problem is how to handle the incoming string. My thought is to convert it to a long, but there doesn't seem to be enough info in "Just Java 2" as to how to work with type long. I took me a while just to figure out how to convert the string to a long and to put an "l" after the 999999999999 when checking to see if the number entered is within range. Should I create a long object? Where do I learn to work with long objects? Can I parse out or substring out a long like I can an int?

Chuck
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're on the right track. Just like the Integer class has a method to parse a String into an int, the Long class has a method to parse a String into a long. A long is a primitive, not an object. You can use it just like you do an int, only it holds more. You might find this Campfire story helpful.

A Long object is not the same as a long primitive. Substrings are only for use with String objects. A long number has the possibility of being larger than an int. Other than that, they're pretty much the same. An int is composed of 32 bits so it can hold a number that is 2 to the 31st power, and a long is composed of 64 bits so it can hold a number that is 2 to the 63rd power.
[ August 20, 2006: Message edited by: Marilyn de Queiroz ]
reply
    Bookmark Topic Watch Topic
  • New Topic