Java Tutorial
This java program is used to convert the temperature from Fahrenheit to Celsius scale.
Temperature in Celsius = ((Temperature in Fahrenheit - 32)*5)/9
import java.util.Scanner; public class FahrenheitToCelsius { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.println("Temparature Fahrenheit to Celsius Conversion"); System.out.println("---------------------------------------------"); System.out.print("Temperature in Fahrenheit: "); int temperatureFh = in.nextInt(); float temperatureCs = (((float)temperatureFh-32)*5)/9; System.out.println("Temperature in Celsius ("+temperatureFh+" Fh): "+ temperatureCs); } }Output:
D:\Java_Programs>javac FahrenheitToCelsius.java D:\Java_Programs>java FahrenheitToCelsius Temparature Fahrenheit to Celsius Conversion --------------------------------------------- Temperature in Fahrenheit: 100 Temperature in Celsius (100 Fh): 37.77778
This java program is used to convert the temperature from Celsius to Fahrenheit scale.
Temperature in Fahrenheit = ((9*Temperature in Celsius)/5)+35
import java.util.Scanner; public class CelsiusToFahrenheit { public static void main(String args[]) { Scanner in = new Scanner(System.in); System.out.println("Temparature Celsius to Fahrenheit Conversion"); System.out.println("---------------------------------------------"); System.out.print("Temperature in Fahrenheit: "); float temperatureCs = in.nextFloat(); float temperatureFh = (9*temperatureCs/5)+32; System.out.println("Temperature in Fahrenheit ("+temperatureCs+" Celsius): "+ temperatureFh); } }Output:
D:\Java_Programs>javac CelsiusToFahrenheit.java D:\Java_Programs>java CelsiusToFahrenheit Temparature Celsius to Fahrenheit Conversion --------------------------------------------- Temperature in Fahrenheit: 37.77778 Temperature in Fahrenheit (37.77778 Celsius): 100.0
Java Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page