In this exercise you will create a temperature converter whi
Solution
FahrenheitToCelsius.java
import java.util.Scanner;
public class FahrenheitToCelsius {
   public static void main(String[] args) {
        //Declaring variables
        int choice;
       
        //Scanner class object is used to read the inputs entered by the user
        Scanner sc=new Scanner(System.in);
        do
        {
            //Displaying the menu
            System.out.println(\"\ :: Menu ::\");
            System.out.println(\"1.Fahrenheit to Celsius\");
            System.out.println(\"2.Celsius to Fahrenheit\");
            System.out.println(\"3.Exit\");
           
            //Getting the user choice
            System.out.print(\"Enter choice :\");
            choice=sc.nextInt();
           
            //Based on the choice .The corresponding case will get executed.
            switch(choice)
            {
            case 1:{
               
                //Declaring variables
                String strfah,strcel;
                double fahrenheit,celsius;
               
               
                //Getting the temperature value in Fahrenheit entered by the user
                System.out.print(\"\ Enter the Temperature in Fahrenheit(F):\");
                strfah=sc.next();
                int index=strfah.indexOf(\"F\");
               
                //Parsing the String to Double
                fahrenheit=Double.parseDouble(strfah.substring(0,index));
               
                //Converting the fahrenheit to celsius
                celsius=Math.floor(((fahrenheit-32)*5/9) * 1000) / 1000.0;
               
                //Concatenating with \"C\" by converting the celsius value to String
                strcel=String.valueOf(celsius)+\"C\";
               
                //Displaying the output
                System.out.println(\"\ The Temperature in Celsius(C) is \"+strcel);
               
                continue;
               
            }
            case 2:{
                //Declaring variables
                String strfah,strcel;
                double fahrenheit,celsius;
               //Getting the temperature value in Celsius entered by the user
                System.out.print(\"\ Enter the Temperature in Celsius(C):\");
                strcel=sc.next();
                int index=strcel.indexOf(\"C\");
               
                //Parsing the String to Double
                celsius=Double.parseDouble(strcel.substring(0,index));
               
                //Converting the celsius to fahrenheit
                fahrenheit=Math.floor((((celsius*9)/5)+32) * 1000) / 1000.0;
   
                //Concatenating with \"F\" by converting the Fahrenheit value to String
                strfah=String.valueOf(fahrenheit)+\"F\";
               
                //Displaying the output
                System.out.println(\"\ The Temperature in Fahrenheit(F) is \"+strfah);
                continue;
            }
            case 3:{
                System.out.println(\"** Program Exit **\");
                break;
            }
            default:{
                System.out.println(\"Invalid inttput.\");
                continue;
            }
            }
           
   
        }while(choice!=3);
       
    }
}
______________________
Output:
 :: Menu ::
 1.Fahrenheit to Celsius
 2.Celsius to Fahrenheit
 3.Exit
 Enter choice :1
Enter the Temperature in Fahrenheit(F):8F
The Temperature in Celsius(C) is -13.334C
:: Menu ::
 1.Fahrenheit to Celsius
 2.Celsius to Fahrenheit
 3.Exit
 Enter choice :2
Enter the Temperature in Celsius(C):12.5C
The Temperature in Fahrenheit(F) is 54.5F
:: Menu ::
 1.Fahrenheit to Celsius
 2.Celsius to Fahrenheit
 3.Exit
 Enter choice :3
 ** Program Exit **
____________Thank You



