Temperature Conversion Program in Java
Published 2 years, 10 months ago in JavaHere's a simple program to convert temperatures between degrees Celcius, Fahrenheit and Kelvin written in Java. There's no GUI used here - all output is done via the command line.
The forumulae for the conversions were obtained from Temperature conversion forumlas on Wikipedia
File: Converter.java
JAVA:
-
/**
-
* Conversion between temperatures in Celcius, Fahrenheit and Kelvin
-
* Uses conversion forumulas from the wikipedia:
-
* http://en.wikipedia.org/wiki/Temperature_conversion_formulas
-
* User: Steven
-
* Date: 27-Dec-2005
-
*/
-
public class Converter {
-
public Converter()
-
{
-
-
}
-
-
// Method to convert from degrees Celcius to degrees Fahrenheit
-
public static float celciusToFahrenheit(float degCelcius)
-
{
-
float degFahrenheit;
-
degFahrenheit = degCelcius * 9/5 + 32;
-
return degFahrenheit;
-
}
-
-
// Method to convert from degrees Fahrenheit to degrees Celcius
-
public static float fahrenheitToCelcius(float degFahrenheit)
-
{
-
float degCelcius;
-
degCelcius = (degFahrenheit - 32) * 5/9;
-
return degCelcius;
-
}
-
-
// Method to convert from degrees Celcius to degrees Kelvin
-
public static float celciusToKelvin(float degCelcius)
-
{
-
float degKelvin;
-
degKelvin = degCelcius + 273.15f;
-
return degKelvin;
-
}
-
-
// Method to convert from degrees Kelvin to degrees Celcius
-
public static float kelvinToCelcius(float degKelvin)
-
{
-
float degCelcius;
-
degCelcius = degKelvin - 273.15f;
-
return degCelcius;
-
}
-
-
// Main method demonstrating usage of above methods
-
{
-
-
-
-
// to convert from Kelvin to Fahrenheit, combine two methods:
-
}
-
}
If you have a low-traffic website, consider joining the Money4Banners advertising network. They will pay you £10 + £5 each month for displaying a small advert on three of your pages, regardless of traffic. American webmasters are welcome, and since £10 == $20, you make more!
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (3)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Puzzles (1)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
No Responses to “Temperature Conversion Program in Java”
Please Wait
Leave a Reply
You must log in to post a comment.