輸出的結果與手算的結果不一致,不知道是哪里出現了錯誤。向各位大神們求助!
import java.text.DecimalFormat;
import java.util.Scanner;
class Temperature {
private static double fTemp;
Temperature(){
double fTemp;
}
//Create one field
public static void main(String[] args) {
double fTemp;
}
//A method named toCelsius that returns the temperature (value of fTemp) in Celsius
public static double toCelsius(){
DecimalFormat df = new DecimalFormat("0.00");
String a = df.format((double) 5/9);
double b = Double.parseDouble(a);
double result = (fTemp - 32) * b;
return result;
}
//A method named toKelvin that returns the temperature (value of fTemp) in Kelvin
public static Double toKelvin(){
DecimalFormat df = new DecimalFormat("0.00");
String a = df.format((double) 5/9);
double b = Double.parseDouble(a);
double result = (fTemp + 459.67) * b;
return result;
}
}
class TemperatureDemo {
public static void main(String[] args) {
Temperature demo = new Temperature();
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter the Fahrenheit temperature: ");
double fTemp = Double.parseDouble(keyboard.nextLine());
//Convert input temperature to be rounded to 2 decimal places.
DecimalFormat df = new DecimalFormat("#.00");
System.out.print("Celsius Temperature: ");
//Print the temperature in Celsius using the toCelsius method of Temperature object
System.out.println(df. format(Temperature.toCelsius()));
System.out.print("Kelvin Temperature: ");
//Print the temperature in Kelvin using the toKelvin method of Temperature object
System.out.println(df. format(Temperature.toKelvin()));
}
}
下面是要求
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/269938.html
標籤:Java相關
上一篇:求大佬給個eclipseJAVA簡單程式代碼,不需要表單
下一篇:求解
