Thursday, June 19, 2014

Elementary Programming; Exercise No. 4

Write a program that converts pounds into kilograms. The program prompts the user to enter a number in pounds, converts it to kilograms, and displays the result. One pound is  0.454 kilograms.

Solution:

public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   double pounds, kilograms;

   System.out.print("Enter the value of pounds:");
   pounds = s.nextDouble();

   kilograms = pounds * 0.454;

   System.out.print("The value in kilograms for " + pounds + " pounds is " + kilograms + ".");
}

No comments:

Post a Comment

Author