做一个单位转换的java程序
发布网友
发布时间:2022-07-30 01:09
我来回答
共2个回答
热心网友
时间:2024-12-14 13:54
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 >= 1 && fathomInt <= 10){
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)整数:
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 >= 1 && fathomInt <= 10){
System.out.println("Fathom Meter");
for(int i = 0 ; i < fathomInt ; 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
Fathom Meter
1 1.8288
2 3.6576
3 5.4864
4 7.3152
5 9.144
6 10.9728
热心网友
时间:2024-12-14 13:55
import java.math.BigDecimal;
public class test {
public static void main(String[] args){
for(int i = 1; i <= 10; i ++){
BigDecimal b0 = new BigDecimal(String.valueOf(i));
BigDecimal b1 = new BigDecimal("1.8288");
BigDecimal b2 = b0. multiply(b1);
System.out.println(b0 + " Fathoms = " + b2 + " m");
}
}
}