Write a java program to Temperature Conversion Calculator

 Temperature Conversion Calculator

1. Convert temperature Celsius to Fahrenheit

2. Convert temperature Celsius to Kelvin

3. Convert temperature to Fahrenheit to Celsius

4. Convert temperature to Fahrenheit to Kelvin

5. Convert temperature Kelvin to Celsius

6. Convert temperature Kelvin to Fahrenheit

Program:

  1. import java.util.Scanner;

    public class Temprature_program {

        public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);

            System.out.println("Enter temprature : ");

            double temp = sc.nextDouble();

            System.out.println("Enter temperature units : \nC - Celsius\nF - Fahrenheit\nK - Kelvin ");

            char unit = sc.next().charAt(0);

            double celsius, fahrenheit, kelvin;

            if (unit == 'C' || unit == 'c') {

                fahrenheit = (temp * 9) / 5 + 32;

                System.out.println("Celsius to Fahrenheit value of given temperature is : " + fahrenheit + " F");

                kelvin = temp + 273.15;

                System.out.println("Celsius to Kelvin value of given temperature is : " + kelvin + " K");

            } else if (unit == 'F' || unit == 'f') {

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

                System.out.println("Fahrenheit to Celsius value of given temperature is : " + celsius + " C");

                kelvin = (temp + 459.67) * 5 / 9;

                System.out.println("Fahrenheit to Kelvin value of given temperature is : " + kelvin + " K");

            } else if (unit == 'K' || unit == 'k') {

                celsius = temp - 273.15;

                System.out.println("Kelvin to Celsius value of given temperature is : " + celsius + " C");

                fahrenheit = (temp * 9) / 5 - 459.67;

                System.out.println("Kelvin to Fahrenheit value of given temperature is : " + fahrenheit + " F");

            } else {

                System.out.println("Please enter correct unit....");

            }

        }

    }

Output:

If condition: Entered C

Else if condition: Entered F

Else if condition: Entered K

Else condition: Entered none of above



Share:

No comments:

Post a Comment

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me