java重量单位转换代码 java重量单位转换代码是多少

做一个单位转换的java程序public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("单位换算,1 fathom= 1.8288 m (1英寻=1.8288米)");
System.out.println("请输入fathom值(1~10)整数:");
int fathomInt = sc.nextInt();
if(fathomInt = 1fathomInt = 10){
System.out.println(fathomInt+" fathom = "+(fathomInt*1.8288)+"m");
【java重量单位转换代码 java重量单位转换代码是多少】}else{
System.out.println("请正确输入fathom!");
}
sc.close();
}
运行结果
单位换算,1 fathom= 1.8288 m (1英寻=1.8288米)
请输入fathom值(1~10)整数:
2
2 fathom = 3.6576m
这两个看你需要哪一个
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("单位换算,1 fathom= 1.8288 m (1英寻=1.8288米)");
System.out.println("请输入fathom值(1~10)整数:");
int fathomInt = sc.nextInt();
if(fathomInt = 1fathomInt = 10){
System.out.println("FathomMeter");
for(int i = 0 ; ifathomInt ; i++){
System.out.println((i+1)+""+((i+1)*1.8288));
}
//System.out.println(fathomInt+" fathom = "+(fathomInt*1.8288)+"m");
}else{
System.out.println("请正确输入fathom!");
}
sc.close();
}
运行结果
单位换算,1 fathom= 1.8288 m (1英寻=1.8288米)
请输入fathom值(1~10)整数:
6
FathomMeter
11.8288
23.6576
35.4864
47.3152
59.144
610.9728
数据单位转换工具java代码import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class UnitTransfer extends JFrame{
private final int WIDTH = 400, HEIGHT = 300;//窗口默认java重量单位转换代码的宽度、高度
private JLabel lblInUnit=new JLabel("输入单位");
private JComboBox cboIn=new JComboBox(new String[]{"", ""});
private JLabel lblIn=new JLabel("输入数值");
private JTextField txtIn=new JTextField("10");
private JLabel lblOutUnit=new JLabel("输出单位");
private JLabel lblResult=new JLabel("显示结果");
private JLabel txtResult=new JLabel("结果");
private JComboBox cboOut=new JComboBox(new String[]{"", ""});
private JButton btnTrans = new JButton("转换");
private JButton btnClear = new JButton("清空");
private JRadioButton rdLeng = new JRadioButton("长度");
private JRadioButton rdWeig = new JRadioButton("时间");
private String [] lengthUnit={"米", "分米", "厘米", "毫米"};
private String [] timeUnit={"天", "时", "分", "秒"};
public UnitTransfer(){
super("简单的单位转换器 Beta");
this.setSize(WIDTH, HEIGHT);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ButtonGroup group = new ButtonGroup();
group.add(rdLeng);
group.add(rdWeig);
this.getContentPane().add(rdLeng);
this.getContentPane().add(rdWeig);
this.getContentPane().add(btnTrans);
this.getContentPane().add(btnClear);
this.getContentPane().add(lblIn);
this.getContentPane().add(txtIn);
this.getContentPane().add(lblInUnit);
this.getContentPane().add(cboIn);
this.getContentPane().add(lblResult);
this.getContentPane().add(txtResult);
this.getContentPane().add(lblOutUnit);
this.getContentPane().add(cboOut);
this.setVisible(true);
this.doLayout();
btnTrans.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
doConvert();
}
});
btnClear.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txtIn.setText("0");
txtResult.setText("0");
}
});
rdLeng.addActionListener(new ActionListener(){

推荐阅读