wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes Another question, already. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Another question, already." Watch "Another question, already." New topic
Author

Another question, already.

Tony VanHorn
Ranch Hand

Joined: Dec 13, 2006
Posts: 74
So I got my nitpick back for Grains, actually got it back twice today. I am having a difficult time with probably one of the easier assignments, but for some reason I can't figure it out. I have been told that double precision is not accurate enough for the assignment, so could somebody go over the differences between the three: long, float, double

long - 2^64
float - 2^32
double - 2^64
(all are signed)

is that correct and if so, what am I suppose to use instead of double, because when I use long I get a -2 (like an unplanned overflow). Plus I think I have found the method that I was suppose to use, but it only comes in double, not vanilla, cholocate, or long. Any help would be greatly appreciated.

Thanks again
Tony
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Tony VanHorn:
... so could somebody go over the differences between the three: long, float, double

long - 2^64
float - 2^32
double - 2^64
(all are signed)

is that correct and if so, what am I suppose to use instead of double, because when I use long I get a -2 (like an unplanned overflow). Plus I think I have found the method that I was suppose to use, but it only comes in double, not vanilla, cholocate, or long. Any help would be greatly appreciated.


You're correct in concluding that a long won't work for problem Java-6.

The clue is in the problem statement...you need to follow the link to the Sun web site and find a class that will provide you with the numeric range you need to solve the problem.

A double provides a floating point data type. A double will give you an answer something like 9.223372E18. It won't give you the exact answer, which is 9223372036854775808 grains on the 64th square. Hence the challenge of this problem: find a class that mimics a data type that covers a number this big.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Tony VanHorn
Ranch Hand

Joined: Dec 13, 2006
Posts: 74
So, which is the java standard library. Is it just the java.lang? If it is, then I wouldn't be able to use java.Math. If it isn't, then I need to find some sort of reading that can help me better understand classes/packages.

Tony
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
So, which is the java standard library. Is it just the java.lang?

Yes, java.lang is the standard java library.

If it is, then I wouldn't be able to use java.Math. If it isn't, then I need to find some sort of reading that can help me better understand classes/packages.

You're looking for a class that is not in java.lang.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41057
    
  43
Originally posted by Marilyn de Queiroz:
So, which is the java standard library. Is it just the java.lang?

Yes, java.lang is the standard java library.


Hmm, I've never heard the therm "standard Java library" used to indicate just the java.lang package. It generally means all of java.*, and often javax.* packages as well if they're part of J2SE.


Ping & DNS - my free Android networking tools app
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I deleted many of the posts in this thread because we don't want to give a student the answer, we want to help him find the correct package and class by providing information on how he can find that for himself.

You have a point, Ulf. Let me clarify my statement. The java.lang package is available for developers to use without adding import statements to the code. Classes in other packages in the j2sdk do not require a separate jar, but they do need to be imported.

We are looking for a class in this assignment is not in the java.lang package, and primitives (int, long, float or double) are not classes.

Tony, do you have the Just Java 2 book? If so, you can find a hint in the chapter on Names, Operators and Accuracy.
[ March 17, 2007: Message edited by: Marilyn de Queiroz ]
Tony VanHorn
Ranch Hand

Joined: Dec 13, 2006
Posts: 74
I have the book, and thanks. I will look there.
To complete this assignment, you will need to find a class in the Java standard library that you have not used yet.

This is the quote from the assignment I was having difficulty with. So, the class I am looking for is in the java.*, which is really what is consider the standard library. Sorry if my questions seem dense, I just have to clarify for myself. Thanks

Tony
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Originally posted by Tony VanHorn:
So, the class I am looking for is in the java.* ...


Yep, that'll be yer huntin' grounds pardner.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
You ask good questions, Tony.
 
Consider Paul's rocket mass heater.
 
subject: Another question, already.
 
Similar Threads
float insted of double
Is Float more Specific than Double
Doubt in implicit/explicit conversions
Widening conversion
Casting and shadowing questions.