Java简单题 如何使结果保留小数点一位
importjavax.swing.JOptionPane;importjava.math.*;publicclasswendu{publicstaticvoidmain...
import javax.swing.JOptionPane;
import java.math.*;
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);
JOptionPane.showMessageDialog(
null,"华氏温度" + huashi + '\n' + "相应的摄氏温度" + sheshi,"华氏温度/摄氏温度转换",
JOptionPane.INFORMATION_MESSAGE);
}
} 展开
import java.math.*;
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);
JOptionPane.showMessageDialog(
null,"华氏温度" + huashi + '\n' + "相应的摄氏温度" + sheshi,"华氏温度/摄氏温度转换",
JOptionPane.INFORMATION_MESSAGE);
}
} 展开
2个回答
展开全部
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 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);
}
}
TableDI
2024-07-18 广告
2024-07-18 广告
Excel表格中的计数函数主要用于统计单元格区域中满足特定条件的数值或非空单元格的数量。最常用的计数函数是`COUNT`和`COUNTA`。`COUNT`函数用于统计选定区域内数值型单元格的数量,忽略文本和空单元格。而`COUNTA`函数则...
点击进入详情页
本回答由TableDI提供
展开全部
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);
}
}
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);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询