Computer Science, asked by ghoshalmoumita19, 4 months ago

write a program in java to input any temperature in Farehenite and convert into celcius using scanner class​

Answers

Answered by Anonymous
1

Answer:

import java.util.Scanner;

public class temperature

{

   public static void main (String a[])

   {

       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.println(" 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.println("Enter temperature in Celsius: ");

           ct = in.nextDouble();

           ft = 9.0/5.0 * ct + 32;

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

           break;

           

           default :

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

       }

   }

}

Similar questions