In: Computer Science
java language NetBeans
Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
I have created java application named WeightConversion in NetBeans IDE
package weightconversion;
import java.util.*;
public class WeightConversion {
public static void main(String[] args) {
//declare variables
double kg_weight, pound_weight;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the weight of the person in kilograms: ");
//takes weight entered by user and stores it in a kg_weight variable
kg_weight = sc.nextDouble();
//convert kg to pound
pound_weight = 2.2 * kg_weight;
//String.format("%.2f",value) is used to round the value upto two digits after point
System.out.println( String.format("%.2f",kg_weight) + " kilogram = " + String.format("%.2f", pound_weight) + " pounds");
}
}