Simple Java program to convert Celsius degrees to Fahrenheit degrees and Fahrenheit degrees to Celsius degrees.
import java.util.Scanner; //? 2017 TheFlyingKeyboard and released under MIT License //theflyingkeyboard.net public class CelsiusFahrenheit { public static void main(String[] args) { Scanner input = new Scanner(System.in); char choice; double temperature; System.out.println("C - convert Celsius to Fahrenheit, F - convert Fahrenheit to Celsius"); choice = input.next().charAt(0); choice = Character.toLowerCase(choice); System.out.print("Enter temperature value: "); temperature = input.nextDouble(); if(choice == 'c'){ System.out.println(temperature + " degrees Celsius is equal to " + CelsiusToFahrenheit(temperature) + " degrees Fahrenheit"); }else{ System.out.println(temperature + " degrees Fahrenheit is equal to " + FahrenheitToCelsius(temperature) + " degrees Celsius"); } } static double CelsiusToFahrenheit(double n) { return (n * 1.8 + 32); } static double FahrenheitToCelsius(double n) { return ((n - 32) / 1.8); } }
Java Conversion Between Celsius And Fahrenheit Degrees