• Post Reply Bookmark Topic Watch Topic
  • New Topic

why it's 0.0  RSS feed

 
Bin Qian
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,thanks very much!
the problem is

but the result is :
The volume of the Earth is 0.0 cubic miles,the volume of the sun is 0.0 cubic miles,and the ratio of the volume of the Sun to the volume of the Earth is NaN!

thanks for telling me why!
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run your code, I get
The volume of the Earth is 1.723854720877791E11 cubic miles,the volume of the sun is 2.54160588899484096E17 cubic miles,and the ratio of the volume of the Sun to the volume of the Earth is 1474373.5990122468!

However, note that your calculations will be incorrect because you are doing integer division and the decimal values will be chopped off.
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also note that your main() method creates an object named Volume, but the name of the class containing main() is Volume0. Do you happen to have another class lying around in your directory named "Volume"??
 
Bin Qian
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohh..
I know!that's so inattention i'm!
thank you very much Marilyn!
oh yes!there is another class named Volume in the same directory!that is a simple version,in that version,i have't use encapsulation!so the problem..
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code calls static methods in non-static way. This works but may be confusing

myVolume seems to be used in the above code but actually it is not.

Another problem is that result of 4/3 is 1. Change

to
 
Bin Qian
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.i'll notice that !
thank you very much!Vlado
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!