第二章第四题(将磅转换为千克)(convert pound to kilogram)

    科技2022-07-10  241

    第二章第四题(将磅转换为千克)(convert pound to kilogram)

    2.4(将磅转换为千克)编写程序,将磅数转换为千克数。程序提示用户输入磅数,然后转换成千克并显示结果。1磅等于0.454千克。 下面是一个运行示例: Enter a number in pounds:55.5 55.5 pounds is 25.197 kilograms

    2.4(convert pounds to kilograms) Write a program that converts pound to kilogram.The program prompts the user to enter a number in pound, converts it to kilogram, and displays the result. one pound is 0.454 kilograms. Here is a simple run: Enter a number in pounds:55.5 55.5 pounds is 25.197 kilograms

    参考代码:

    package chapter02; import java.util.*; public class Code_04 { public static void main(String[] args) { double pound,kilogram; System.out.print("Enter a number in pounds : "); Scanner pound_input = new Scanner(System.in); pound = pound_input.nextDouble(); kilogram = pound * 0.454; System.out.println(pound + " pounds is " + kilogram + " kilograms"); pound_input.close(); } } 结果显示: Enter a number in pounds : 55.5 55.5 pounds is 25.197 kilograms Process finished with exit code 0
    Processed: 0.032, SQL: 8