java 怎样把下面的打双杆的对话框代码改成一个对话框输出
importjavax.swing.JOptionPane;publicclassPeriMeter{privatestaticfloatPI=3.14f;publics...
import javax.swing.JOptionPane;
public class PeriMeter{
private static float PI=3.14f;
public static void main(String args[]){
String s=JOptionPane.showInputDialog("请输入圆的半径:");
double d=Double.parseDouble(s);
double c=2*PI*d;
double a=PI*d*d;
// JOptionPane.showMessageDialog(null,"半径为”+s+”的圆:\n");
// JOptionPane.showMessageDialog(null,"周长="+c+"\n");
//JOptionPane.showMessageDialog(null,"面积="+a+"\n");
}
} 展开
public class PeriMeter{
private static float PI=3.14f;
public static void main(String args[]){
String s=JOptionPane.showInputDialog("请输入圆的半径:");
double d=Double.parseDouble(s);
double c=2*PI*d;
double a=PI*d*d;
// JOptionPane.showMessageDialog(null,"半径为”+s+”的圆:\n");
// JOptionPane.showMessageDialog(null,"周长="+c+"\n");
//JOptionPane.showMessageDialog(null,"面积="+a+"\n");
}
} 展开
展开全部
String msg = "半径为"+s+"的圆:\n" + "周长="+c+"\n" + "面积="+a+"\n";
JOptionPane.showMessageDialog(null, msg);
追问
那怎样控制小数点,比如我要保留后三位
追答
示例:(关键是println的参数)
import java.text.*;
System.out.println("A=" + new DecimalFormat("#0.000").format(12.33445));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询