Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Calc not working correctly?
Krystyna Speer
Greenhorn
Posts: 2
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can someone please help me figure out why this only shows 0 for Celsius?
I'm sure it's something small, but I'm really just not sure what.
// Supposed to convert a temperature in degrees Fahrenheit to // degrees Celsius, but only returns 0 for Celsius temperatures? public class Ex6 { public static void main(String[] args) { double c; //Celsius System.out.println("Temperatures \n------------ \nFahrenheit \t Celsius"); for (int f = 0; f <= 20; f++) // Loops through 0 - 20 degrees Fahrenheit. { c = ((f-32)*(5/9)); // This is the formula to convert a degree in Fahrenheit to Celsius, according to my textbook and Google... System.out.println(f+" \t\t "+c); // This ends up only printing 0 for c... } } }
---------
<3 Krys
Prajakta Acharya
Ranch Hand
Posts: 138
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
5 and 9 both being integers, the result of 5/9 is getting type casted to integer. That means 0.5555555 is getting converted to 0.
Use 5.0/9.0 and
test
.
Thanks,
Prajakta
Regards,
Prajakta
Krystyna Speer
Greenhorn
Posts: 2
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Oh goodness, I knew it was something simple. It was driving me crazy. Thank you.
---------
<3 Krys
Campbell Ritchie
Marshal
Posts: 79177
377
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
And welcome to the Ranch
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
if else statement
storing values in an array and accessing them elsewhere in the program
Back to basics: if statement
comparison methods
equalsIgnoreCase
More...