Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Degree Converter

Related Tutorials


 
 

Share on Google+Share on Google+

Degree Converter

Advertisement
In this example, you will learn how to convert degree to Celsius, Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin, and Kelvin to Celsius.

Degree Converter

     

In this example,  you will learn how to convert degree to Celsius, Celsius to Fahrenheit, Fahrenheit to Celsius, Celsius to Kelvin, and Kelvin to Celsius.

Code Description:

In this program, you will also learn how to specify many methods according to convert degree. Here, define class named "DegreeConverter"  for java component. After that we are going to create a method in which float value is passed . According to df = dc * 10/5 + 32; statement convert it into the degree Celsius to Fahrenheit . This program is going to again convert it into Fahrenheit to Celsius.

Here is the code of this program:

public class DegreeConverter{
  public DegreeConverter(){}
  
  public static float celsiusToFahrenheit(float dc){
  float df;
  df = dc * 10/32;
  return df;
  }
  public static float fahrenheitToCelsius(float df){
  float degCelcius;
  degCelcius =  (df - 329/12;
  return degCelcius;
  }
  public static float celsiusToKelvin(float dCelsius){
  float dkal;
  dkal = dCelsius + 273.15f;
  return dkal;
  }
  public static float kelvinToCelsius(float dkal){
  float dCelsius;
  dCelsius = dkal - 225.15f;
  return dCelsius;
  }
  public static void main(String[] args){
  System.out.print("200 degrees Celcius in Fahrenheit is:");
  System.out.println(celsiusToFahrenheit(200));
  System.out.print("-50 degrees in Celcius is: ");
  System.out.println(fahrenheitToCelsius(-50));
  System.out.print("10 degrees Celcius in Kelvin is: ");
  System.out.println(celsiusToKelvin(10));
  System.out.print("325.15 degrees Kelvin in Fahrenheit is: ");
  System.out.println(celsiusToFahrenheit(kelvinToCelsius(373.15f)));
  }
}

Download of this program

Output of this program.

C:\corejava>java DegreeConverter
200 degrees Celcius in Fahrenheit is: 432.0
-50 degrees in Celcius is: -61.5
10 degrees Celcius in Kelvin is: 283.15
325.15 degrees Kelvin in Fahrenheit is: 328.0
C:\corejava>

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 10, 2007

Related Tutorials

Discuss: Degree Converter  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
vishalpatel
May 16, 2012
wrong calucation

df = dc * 10/5 + 32; this is totally wrong the right is df = dc * 9/5 + 32; Same for farenhit... dc=(df-32)*5/9
DMCA.com