I need to create a program that converts a given kg value and converts it to lbs
ID: 3655535 • Letter: I
Question
I need to create a program that converts a given kg value and converts it to lbs. both kg and pound outputs need to be shown with 2 decimal places. the code I have right now does the conversion, but I cannot figure out the decimal places code. Please help. import javax.swing.JOptionPane; import java.text.DecimalFormat; public class KilogramToPoundsConversion { public static void main(String[] args) { double kgs, pounds, totpounds; String poundsStr, kgsStr, outputStr; kgsStr = JOptionPane.showInputDialog("Enter kgs: "); kgs = Double.parseDouble(kgsStr); totpounds = 2.20 * (kgs); outputStr = "kgs: " + kgs + " " + "pounds: " + totpounds + " lbs "; JOptionPane.showMessageDialog (null, outputStr, "Kilograms To Pounds Conversion", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }Explanation / Answer
package com.cramster.nov5; import javax.swing.JOptionPane; import java.text.DecimalFormat; public class KilogramToPoundsConversion { public static void main(String[] args) { double kgs, pounds, totpounds; String poundsStr, kgsStr, outputStr; kgsStr = JOptionPane.showInputDialog("Enter kgs: "); kgs = Double.parseDouble(kgsStr); totpounds = 2.20 * (kgs); outputStr = String.format("kgs: " + kgs + " " + "pounds: %.2f lbs ",totpounds); JOptionPane.showMessageDialog (null, outputStr, "Kilograms To Pounds Conversion", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.