mathajax

Temperature Conversion between Celsius and Fharenheit

The java code carried out conversion between celsius and Fahrenheit


A switch case used to select choice of conversion , C2F (celsius to Fahrenheit) or F2C (Fahrenheit to celsius) and a input temperature value is given to the selected conversion process.


Fahrenheit to Celsius conversion formula
Fahrenheit to Celsius





celsiucs to fahrenheit conversion formula
Celsius to Fahrenheit








This example  shows how to calculate use these temperature conversion formula

Given     Fharenheit F = 76 and find celsius C = ?

               C  = ( 76 -32)  x  (5/9)

                    =  44 x 0.555

               C  = 24.442

Given     Celsius C = 24 and find  Fharenheit F =?

               F  = (9 x C) / 5   +  32

                    =  (9 x 24) / 5  + 32

                   =   216 / 5  + 32

                  =   43.2   +32

                F  =   75.2




import java.util.Scanner;

public class Cel2Fah {

 public static void main(String[] args) {
  

          System.out.println("Temperature Conversion 
                           (Celsius - Fharenheit) \n");
   String menustr="1- C2F n2- F2C n";
   System.out.println(menustr);
   System.out.println("Select Choice");
 
     Scanner sc = new Scanner(System.in);
     int choice =sc.nextInt();
     double cel=0.0,fah=0.0;
     
     
  switch ( choice ) 
  {  
     case 1:
    
   System.out.println("Enter Celsius value ");
   cel = sc.nextDouble();
   fah = 9.0*cel/5.0+32;
   System.out.println("Fharenheit :  " + fah);
   break;
    
     case 2:
    
   System.out.println("Enter Fharenheit value");
   fah = sc.nextDouble();
   cel = (fah-32)*5.0/9.0;
   System.out.println("Celsius :  " + cel);
   break;
  }
  sc.close();
  
 }

}


Output
Temperature Conversion (Celsius - Fharenheit) 

1- C2F 
2- F2C 

Select Choice
1
Enter Celsius value 
37
Fharenheit :  98.6


Temperature Conversion (Celsius - Fharenheit) 

1- C2F 
2- F2C 

Select Choice
2
Enter Fharenheit value 
96
Celsius :  35.55555555555556

Comments

Popular posts from this blog

Solving System of Linear Equations by Gauss Jordan Elimination

Matrix Forward and Back Substitution

Solve System of Linear Equations by LU Decompose

Chebyshev distance between two points

Binary 1's and 2's Complement