磅转为千克
import javax.swing.JOptionPane; public class Weight { public static void main(String[] args){ String input = JOptionPane.showInputDialog(null,"请输入磅数:","输入框",JOptionPane.QUESTION_MESSAGE); double pounds = Double.parseDouble(input); System.out.println(pounds + " pounds is " + pounds * 0.454 + " kilograms"); } }
编写程序,将磅数转换为千克数。程序提示用户输入磅数,然后转换成千克数并显示结果。一磅等于0.454千克。