做一个单位转换的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(){
推荐阅读
- 动态网站的开发流程,动态网站开发技术项目教程书籍
- 视频号没有企业怎么企业认证,视频号如何进行企业认证
- u盘图片为什么不能预览,u盘里面图片为什么不能看了
- qq空间直播怎么录屏,空间直播游戏录屏有声音吗
- 拍摄翡翠用什么灯光,拍摄翡翠用暖光还是白光
- redis最多,redis最多可以有多少个库
- 显卡硬件加速怎么开,显卡硬件加速怎么开启win11
- linux清除系统命令 linux 清除
- oracle如何导出表字段,oracle导出表字段和说明