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
参考代码:
package chapter02; import java.util.*; public class Code_03 { 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"); FeetInput.close(); } } 结果显示: Enter a value for feet : 16.5 16.5 feet is 5.0325 meters Process finished with exit code 0