Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

One more question, then thats it I promise :) ...

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay this program is supposed to take any integer entered by a user, then strip off the individual digits and sum them up. I just can't work out this last error I keep getting. Any idea how to fix it? Heres the code and the error message...


C:\My Documents\Homework 6\IntSum2.java:32: possible loss of precision
found : double
required: int
num = (InputNum / Math.pow(10, count) % 10);
^
1 error
Not sure why its telling me loss of precision, I think the equation is okay the way it is. I didnt start getting the error untill I put Math.pow into the equation.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hiii..
If you go through JavaDocs then you will find that Math.Pow() return a double and in this case you need to are storing the value in an int datatype.
tgus according to Java when u r storing a bigger datatype into a smaller in which there is possibility of loss of precision then you need to explicitly type cast it..
so u can do this in any of the following manner and your error will be gone..

i hope i have answered your question... if still in doubt please get back
Thanks
Amit
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wonderful, it compiles! thank you
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic