第二章第三题(将英尺转换为米)(convert feet to meters)
程序员文章站
2024-02-29 18:53:16
...
2.3(将英尺转换为米)编写程序,读入英尺数,将其转换成米数并显示结果。1英尺等于0.305米。
下面是运行示例:
Enter a value for feet:16.5
16.5 feet is 5.0325 meters
2.3(convert feet to meters) Write a program that reads a number in feet,convert it to meters,and displays the result.one foot is 0.305 meter.
Here is a simple run:
Enter a value for feet:16.5
16.5 feet is 5.0325 meters
下面是参考答案代码:
import java.util.*;
public class ConvertFeetToMetersQuestion3 {
public static void main(String[] args) {
double Feet,Meters;
System.out.print("Enter a value for feet : ");
Scanner FeetInput = new Scanner(System.in);
Feet = FeetInput.nextDouble();
Meters = Feet * 0.305;
System.out.println(Feet + " feet is " + Meters + " meters");
}
}
运行效果:
注:编写程序要养成良好习惯
如:1.文件名要用英文,具体一点
2.注释要英文
3.变量命名要具体,不要抽象(如:a,b,c等等),形式要驼峰化
4.整体书写风格要统一(不要这里是驼峰,那里是下划线,这里的逻辑段落空三行,那里相同的逻辑段落空5行等等)
下一篇: [拾遗] 字符编码(Encoding)