Computer Science, asked by sudesnapradhandhara, 1 month ago

Using a switch statement, write a menu driven program to convert a given temperature from Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error message should be displayed.
(HINT : C = 5/9 × (F – 32) and F = 1.8 × (C + 32)​

Answers

Answered by lighting2011
2

Answer:

ANSWER

import java.util.Scanner;

public class KboatTemperature

{

   public static void main(String args[]) {

       Scanner in = new Scanner(System.in);

       System.out.println("Type 1 to convert from Fahrenheit to Celsius");

       System.out.println("Type 2 to convert from Celsius to Fahrenheit");

       int choice = in.nextInt();

       double ft = 0.0, ct = 0.0;

       switch (choice) {

           case 1:

               System.out.print("Enter temperature in Fahrenheit: ");

               ft = in.nextDouble();

               ct = 5 / 9.0 * (ft - 32);

               System.out.println("Temperature in Celsius: " + ct);

               break;

           case 2:

               System.out.print("Enter temperature in Celsius: ");

               ct = in.nextDouble();

               ft = 1.8 * ct + 32;

               System.out.println("Temperature in Fahrenheit: " + ft);

               break;

           default:

               System.out.println("Incorrect Choice");

               break;

       }

   }

}

OUTPUT

BlueJ output of Using a switch case statement, write a menu driven program to convert a given temperature from Fahrenheit to Celsius and vice-versa. For an incorrect choice, an appropriate message should be displayed. Hint: c = 5/9 (f-32) and f=1.8 c+32

BlueJ output of Using a switch case statement, write a menu driven program to convert a given temperature from Fahrenheit to Celsius and vice-versa. For an incorrect choice, an appropriate message should be displayed. Hint: c = 5/9 (f-32) and f=1.8 c+32

Explanation:

Similar questions