import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
public class ConvertFahrenheitToCelcius {
public static void main(String[] args) {
System.out.println("This program will convert temperature in fahrenheit into celsius.");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
System.out.println("Enter temperature in Fahrenheit:");
String input = br.readLine();
float tempF = Float.parseFloat(input);
float tempC = (tempF - 32) * 5 / 9;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("Temperature in Celsius:" + df.format(tempC));
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
Tag Archives: celsius
Java program to convert celsius to fahrenheit
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
public class CelsiusToFahrenheit {
public static void main(String[] args) {
System.out.println("This program will convert temperature in celsius into fahrenheit");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
System.out.println("Enter Temperature in Celsius:");
String input = br.readLine();
float tempC = Float.parseFloat(input);
float tempF = tempC * 9 / 5 + 32;
DecimalFormat df = new DecimalFormat("0.00");
System.out.println("Temperature in Fahrenheit:" + df.format(tempF));
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}