Create a temperature converter in java

 Create a temperature converter in java

import java.util.Scanner;

public class TempertureConverter
{
    public static void main(){
    double celsius,fahrenheit,kelvin;
    int option;
    Scanner input = new Scanner(System.in);
    System.out.println("Press 1 celsius to fahrenheit");
    System.out.println("Press 2 fahrenheit to celsius");
    System.out.println("Press 3 celsius to kelvin");
    System.out.println("Press 4 kelvin to celsius");
    System.out.println("Press 5 fahrenheit to kelvin");
    System.out.println("Press 6 kelvin to fahrenheit");
    option=input.nextInt();
    switch(option){
        case 1:System.out.println("celsius to fahrenheit");
                System.out.println("Enter celsius"); 
                celsius=input.nextInt();
                fahrenheit=32+celsius*9/5;
                System.out.println("fahrenheit :="+fahrenheit);
                break;
        case 2:System.out.println("fahrenheit to celsius");
                System.out.println("Enter fahrenheit"); 
                fahrenheit=input.nextInt();
                celsius=(fahrenheit-32)*5/9;
                System.out.println("celsius :="+celsius);
                break;
        case 3:System.out.println("celsius to kelvin");
                System.out.println("Enter celsius"); 
                celsius=input.nextInt();
                kelvin=celsius+273.15
                System.out.println("kelvin :="+kelvin);
                break;
        case 4:System.out.println("kelvin to celsius");
                System.out.println("Enter kelvin"); 
                kelvin=input.nextInt();
                celsius=kelvin-273.15
                System.out.println("celsius :="+celsius);
                break;
        case 5:System.out.println("fahrenheit to kelvin");
                System.out.println("Enter fahrenheit"); 
                fahrenheit=input.nextInt();
                kelvin=273.15+(fahrenheit-32)*5/9;
                System.out.println("kelvin :="+kelvin);
                break;
        case 6:System.out.println("Kelvin to fahrenheit");
                System.out.println("Enter Kelvin"); 
                kelvin=input.nextInt();
                fahrenheit=32+(kelvin-273.15)*9/5;
                System.out.println("fahrenheit :="+fahrenheit);
                break;
    }
    }
}
Output
Press 1 celsius to fahrenheit Press 2 fahrenheit to celsius Press 3 celsius to kelvin Press 4 kelvin to celsius Press 5 fahrenheit to kelvin Press 6 kelvin to fahrenheit 2 fahrenheit to celsius Enter fahrenheit 45 celsius :=7.222222222222222

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript

Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java