Description
This basic java example source code reads the temperature in degrees Fahrenheit from console and calculate the equivalent in degrees Celsius.
Degree Fahrenheit to Celsius Conversion Source Code
package com.javatutorialhq.java.examples; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * This basic java example source code * reads temperature in degrees fahrenheit from console input * Java Program to convert Degree Fahrenheit to Celsius */ public class ConvertFahrenheitDegrees { public static void main(String[] args) throws NumberFormatException, IOException { // Declare the reader from console BufferedReader br; // Get the console input for the temperature in degree fahrenheit System.out.println("Temperature in Degree Fahrenheit:"); br = new BufferedReader(new InputStreamReader(System.in)); // assign to float variable the degree fahrenheit float fahrenheit = Float.parseFloat(br.readLine()); // Degrees Fahrenheit to Degree Centigrade Conversion float celsius = (fahrenheit-32)*(5.0f/9.0f); System.out.println("Degree Celsius: "+ celsius); } }
Sample Output
Temperature in Degree Fahrenheit: 12.34 Degree Celsius: -10.922223