Write a program that prompts the user to enter the mass of a person in kilograms
ID: 645210 • Letter: W
Question
Write a program that prompts the user to enter the mass of a person in kilograms and outputs the equivalent weight in pounds.
Output both the mass and the weight rounded to two decimal places.
I need to format this in a way that my output is two decimal places. The program runs but I am missing that key aspect of the assignment. Note- 1 pound = 2.2 kilograms
import java.util.Scanner;
public class Converter {
public static void main (String [ ] args) {
double kilograms;
double pounds;
Scanner input = new Scanner (System.in);
System.out.println ("Enter your mass in kilograms " );
kilograms = input.nextDouble ();
pounds = kilograms * 2.2;
System.out.println (kilograms + "kilograms is equivalent to" + pounds + " pounds " );
}
}
Explanation / Answer
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
?
public class MassofaPersonProgram
{
public static void main(String[] args)
{
String massinkilograms;
String inputstr;
String outputstr;
double kilograms;
inputstr = JOptionPane.showInputDialog("Enter mass in kilograms");
kilograms = Double.parseDouble(inputstr);
outputstr = new DecimalFormat("##.##").format(kilograms* 2.20);
JOptionPane.showMessageDialog(null, outputstr,"Weight in Pounds",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.