【发布时间】:2012-12-19 06:28:46
【问题描述】:
我必须将摄氏温度转换为华氏温度。但是,当我以摄氏度打印温度时,我得到了错误的答案!请帮忙 ! (公式是 c = (5/9) * (f -32)。当我输入 1 代表华氏度时,我得到 c = -0.0。我不知道出了什么问题:s
这里是代码
import java.io.*; // import/output class
public class FtoC { // Calculates the temperature in Celcius
public static void main (String[]args) //The main class
{
InputStreamReader isr = new InputStreamReader(System.in); // Gets user input
BufferedReader br = new BufferedReader(isr); // manipulates user input
String input = ""; // Holds the user input
double f = 0; // Holds the degrees in Fahrenheit
double c = 0; // Holds the degrees in Celcius
System.out.println("This program will convert the temperature from degrees Celcius to Fahrenheit.");
System.out.println("Please enter the temperature in Fahrenheit: ");
try {
input = br.readLine(); // Gets the users input
f = Double.parseDouble(input); // Converts input to a number
}
catch (IOException ex)
{
ex.printStackTrace();
}
c = ((f-32) * (5/9));// Calculates the degrees in Celcius
System.out.println(c);
}
}
【问题讨论】:
-
非常感谢大家 :) 我很困惑哈哈 :p
标签: java temperature