wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Calculating with Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calculating with Java" Watch "Calculating with Java" New topic
Author

Calculating with Java

Shirl Diva
Greenhorn

Joined: Sep 09, 2002
Posts: 21
Is there a problem, in java, when it comes to calculating arithmetic problems that are more than two pronged. Why am I having so much trouble trying to multiply 2 * radius * diameter??
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
I don't know. What trouble are you having? What are the types of those variables?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Cain Silverbane
Greenhorn

Joined: Jul 22, 2002
Posts: 13
hrmm... shouldnt have trouble, I wouldn't think... what exactly are you doing?
doing things such as x * y * z should be just as easy as x * y. Be sure to remember to have it all stored into something:
volume = length * height * width;


~ Silverbane ~
Shirl Diva
Greenhorn

Joined: Sep 09, 2002
Posts: 21
I was supposed to write a tiny program that prompted the user for a value, for the radius of a circle. The pgm then calcs the diameter, area, and circumference of the circle from that value. I had all of my variables in place. I tried to do something simple like circ = radius * pi * diameter. It would not take it. The error msg went something like this...I can't remember exactly. I can't find my notes either. It said something about me using 'double' int. I looked that up and used the (double) with it and it still wouold not work. I'm sorry guys but I was putting another query up - that's why I was not ready with this one. I am just loaded with problems
Shirl Diva
Greenhorn

Joined: Sep 09, 2002
Posts: 21
I found it!! The error msg is "possible loss of precisiion: double required int." It calculated radius = diameter * 2. When it came to the "Circumference = 2 * Math.PI * Radius - it was having no part of it.
Shirl Diva
Greenhorn

Joined: Sep 09, 2002
Posts: 21
Originally posted by Cain Silverbane:
hrmm... shouldnt have trouble, I wouldn't think... what exactly are you doing?
doing things such as x * y * z should be just as easy as x * y. Be sure to remember to have it all stored into something:
volume = length * height * width;

The variables have been changed from string to integer and the code goes like this "Circumference = 2 * Math.PI * Radius;" The msg that I get is "possible loss of precision; double required int", I went back in and used the (double) and it still didn't accept it.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Try:
Circumference = 2.0d * Math.PI * Radius;
And make sure Circumference and Radius are both doubles.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Math.PI is a double, so the result of your multiplication will be a double. You must store it in a double variable, not an int.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Shirl,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculating with Java