Written by Sai Sameera Thota on February 23, 2013 in Java > Programming

Java Program to Implement Temperature Conversion

GET ALERTS:

Get our Latest updates delivered to your mailbox!

In this program we are going to implement Temperature Conversion using a simple Java Program. In this program we will be converting Fahrenheit to Celsius and Celsius to Fahrenheit.

import java.io.*;
class Tempconv
{
	
		public void celTofar(double cel) throws IOException
		{
			
			double far=(cel*1.8)+32;
			System.out.println("\nFahrenheit : "+far);
		}
		public void farTocel(double far) throws IOException
		{
			double cel=((far-32)*0.55);
			System.out.println("\nCelsius Temperature : "+cel);
		}

		public static void main(String args[]) throws IOException
		{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			Tempconv tc =  new Tempconv();
			System.out.println("\n1. Celsius to Fahrenheit ");
			System.out.println("2. Farenheit to Celsius\n  ");
			System.out.print("Select a coversion: ");
			int select = Integer.parseInt(br.readLine());
			if(select == 1)
			{
				System.out.print("\nEnter celsius temperature : ");
			    double cel=Double.parseDouble(br.readLine()); 
				tc.celTofar(cel);
            }
			else if(select == 2)
			{
			    System.out.print("\nEnter fahrenheit temperature : ");
			    double far=Double.parseDouble(br.readLine()); 
				tc.farTocel(far);
			}
			else
				System.out.print("Enter a valid number");
		}
}

Output:

Tempconv

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: