2.1 将华氏温度转换为摄氏温度
转换公式:摄氏度=(5/9)*(华氏度-32)
public class Exercise2_1{
public static void main(String[] agrs){
//从输入对话框获取华氏温度,返回字符串String input = JOptionPane.showInputDialog(null,"请输入华氏度","Input Dialog Demo",JOptionPane.QUESTION_MESSAGE);double Fahrenheit = Double.parseDouble(input);//将字符串转换为double型值double Celsius = (5.0/9)*(Fahrenheit-32);JOptionPane.showMessageDialog(null,"转换后的摄氏温度为:"+Celsius,"Output Dialog Demo",JOptionPane.INFORMATION_MESSAGE);}}
新闻热点
疑难解答