The Java code is right here to show.
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- class Demo {
- public static void main(String[] args) throws Exception {
- float Ctemperature, Ftemperature;
- Scanner in = new Scanner(System. in );
- BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
- System.out.println("1-Celsius to Fahrenheit..?");
- System.out.println("2-Fahrenheit to Celsius..?");
- System.out.println();
- System.out.print("Select any option: ");
- int select = Integer.parseInt(br.readLine());
- switch (select) {
- case 1:
- System.out.print("Enter temperatue in Celsius: ");
- Ctemperature = in .nextInt();
- Ftemperature = (Ctemperature * 9) / 5 + 32;
- System.out.println("Temperatue in Fahrenheit = " + Ftemperature);
- break;
- case 2:
- System.out.print("Enter temperatue in Fahrenheit: ");
- Ftemperature = in .nextInt();
- Ctemperature = ((Ftemperature - 32) * 5) / 9;
- System.out.println("Temperatue in Celsius = " + Ctemperature);
- break;
- default:
- System.out.println("Wrong choice :(");
- }
- }
- }
Thank you, keep learning and sharing.