• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong with my source code?  RSS feed

 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings, I have two methods one for converting celsius to farenheit and the other method to convert farenheit to Celsius. I am not having the best of luck with these methods. The equations (listed below) are improperly converting the units. I believe that there may be a possible issue with the way the formulae is written. Can some of you heroes please help assess the code for possible solutions.

 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want 5.0/9.0
As you have it it performs integer division resulting in zero.
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You want 5.0/9.0
As you have it it performs integer division resulting in zero.


Excellent, thank you very much for help. I guess that I forgot you can not divide an integer with a double. Thanks for the reminder.
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Naziru Gelajo wrote:
Carey Brown wrote:You want 5.0/9.0
As you have it it performs integer division resulting in zero.


Excellent, thank you very much for help. I guess that I forgot you can not divide an integer with a double. Thanks for the reminder.

Well, yes you can divide an integer with a double, and in that case the integer will be promoted to a double before the divide takes place. Eg 5.0/9
What you have is integer divided by an integer which will throw away any fractional part.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!