Fahrenheit to Celsius convertor in JAVA
import java.io.*;
import java.text.*;
class FahrenheittCelsiusconvertor {
public static void main(String arg[]) throws IOException {
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
DecimalFormat decimalFormat = new DecimalFormat("0.00");
String getValue;
double fahrenheitt = 0.00;
char reply;
do {
System.out.print("\n\t FAHRENHEIT TO CELSIUS CONVERTER");
System.out.print("\n\t -------------------------------\n\n");
System.out.print("ENTER FAHRENHEIT VALUE : ");
// Input routine that will accept numerial values
getValue = stdin.readLine();
fahrenheitt = Integer.parseInt(getValue);
System.out.print("CELSIUS VALUE IS " + decimalFormat.format(fah_cel(fahrenheitt)) + "\n");
System.out.print("\nDO YOU WANT TO continue Y/N : ");
String answer = stdin.readLine();
reply = answer.charAt(0);
} while (reply == 'Y' || reply == 'y');
if (reply == 'n' || reply == 'N') {
System.exit(0);
}
}
// A method to compute the fahrenheit to
// celsius
public static double fah_cel(double f) {
double cel = 0.00;
cel = (5.0 / 9.0) * (f - 32.0);
return (cel);
}
} // End of Code
Post a Comment