import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class wendu {
public static void main(String[] args) {
double huashi;
double sheshi;
// Prompt the user to enter number
String str = JOptionPane.showInputDialog(null, "请输入一个华氏温度",
"华氏温度/摄氏温度转换", JOptionPane.QUESTION_MESSAGE);
huashi = Double.parseDouble(str);
sheshi = (5.0 / 9) * (huashi - 32);
DecimalFormat format = new DecimalFormat("#0.0"); //java.text包里面的DecimalFormat 类
String buf = format.format(sheshi).toString();
JOptionPane.showMessageDialog(null, "华氏温度" + huashi + '\n' + "相应的摄氏温度"
+ buf, "华氏温度/摄氏温度转换", JOptionPane.INFORMATION_MESSAGE);
}
}
import javax.swing.JOptionPane;
import java.math.*;
public class Print {
public static void main(String[] args) {
double huashi;
double sheshi;
// Prompt the user to enter number
String str = JOptionPane.showInputDialog(
null, "请输入一个华氏温度", "华氏温度/摄氏温度转换",
JOptionPane.QUESTION_MESSAGE);
huashi = Double.parseDouble(str);
sheshi = (5.0/9)*(huashi-32);
String s = Double.toString(sheshi);
int i = s.indexOf('.');
String sub = s.substring(0, i + 2);
JOptionPane.showMessageDialog(
null,"华氏温度" + huashi + '\n' + "相应的摄氏温度" + sub,"华氏温度/摄氏温度转换",
JOptionPane.INFORMATION_MESSAGE);
}
}