首页 > 编程 > Java > 正文

Java语言程序设计基础篇原书第六版第二章编程题2.1

2019-11-08 02:31:01
字体:
来源:转载
供稿:网友

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);}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表