Java - Fahrenheit Celsius Converter
Here is Java Source Code for Fahrenheit Celsius Converter.
Source Code
class FahrenheitCelsiusConverter {
public static void main(String[] args) {
String inpstring = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
try
{
System.out.print("Enter a number to use in Fahrenheit and Celsius Converter:");
inpstring = reader.readLine();
double val = Double.parseDouble(inpstring);
double Celsius = (val - 32.0) * 5.0 / 9.0;
double Fahrenheit = (val * (9.0 / 5.0) + 32);
char degree = 248;
System.out.print(val);
System.out.print(degree);
System.out.print("F = ");
System.out.print(Celsius);
System.out.print(degree);
System.out.print("C\n");
System.out.print(val);
System.out.print(degree);
System.out.print("C = ");
System.out.print(Fahrenheit);
System.out.print(degree);
System.out.print("F\n");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Output
D:\Program Files\Java\jdk1.6.0_23\bin>java FahrenheitCelsiusConverter
Enter a number to use in Fahrenheit and Celsius Converter:0
0.0°F = -17.77777777777778°C
0.0°C = 32.0°F
D:\Program Files\Java\jdk1.6.0_23\bin>java FahrenheitCelsiusConverter
Enter a number to use in Fahrenheit and Celsius Converter:32
32.0°F = 0.0°C
32.0°C = 89.6°F
D:\Program Files\Java\jdk1.6.0_23\bin>java FahrenheitCelsiusConverter
Enter a number to use in Fahrenheit and Celsius Converter:-40
-40.0°F = -40.0°C
-40.0°C = -40.0°F
D:\Program Files\Java\jdk1.6.0_23\bin>java FahrenheitCelsiusConverter
Enter a number to use in Fahrenheit and Celsius Converter:98.6
98.6°F = 37.0°C
98.6°C = 209.48°F
|