Computer Science, asked by shila136dasgupta, 1 year ago

using a switch case in java , write a program to convert a given temperature from Fahrenheit to Celsius scale and vice versa

Answers

Answered by Pavani02713
110
Write the default statement.
Attachments:
Answered by lovingheart
65

A program to convert a given temperature from Fahrenheit to Celsius scale and vice versa:

class ConversionofFarenheitandCelsius

{

public static void main(String arg[])  

{

    double farenheit,celsius;

                 Scanner sc=new Scanner(System.in);

    System.out.println("Choose type of conversion \n 1.Fahrenheit to Celsius  \n 2.Celsius to Fahrenheit");

                  int ch=sc.nextInt();

    switch(ch)

    {

    case 1:  System.out.println("Enter  Fahrenheit temperature");

                     farenheit =sc.nextDouble();

       celsius =( farenheit -32)*5/9;

       System.out.println("Celsius temperature is = "+ celsius);

   break;

    case 2:  System.out.println("Enter  Celsius temperature");

                     celsius =sc.nextDouble();

       farenheit =((9* celsius)/5)+32;

       System.out.println("Fahrenheit temperature is = "+ farenheit);

   break;

   default:  System.out.println("please enter a valid choice");

   }  

}  

}

Similar questions