Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Write a java program that prompts the user to enter a weight in pounds and ounces and output the weight expressed in kilograms and grams. One pound is equals to 0.453592 kilograms. Name the program as Weight.java
- Code :
- import java.util.Scanner;
- public class Weight {
- static Scanner sc = new Scanner(System.in);
- public static void main(String [] args)
- {
- //we need variables to hold values that the user will input
- double pounds;
- double ounces;
- double kg;
- double g;
- double kilograms;
- double grams;
- //variables are created
- //the program will ask the user to input number for pounds
- System.out.print("Enter pounds : ");
- pounds = sc.nextDouble();
- //pounds has been declared
- //the program will now ask the user to input number ounces
- System.out.print("Enter ounces : ");
- ounces = sc.nextDouble();
- //ounces has been declared
- //set conversion table : pounds to kilograms
- kg = 0.453592;
- g = 0.02845;
- //conversion computation
- kilograms = pounds*kg;
- grams = ounces*g;
- //display output
- System.out.println("Kilograms : " +kilograms);
- System.out.println("Grams : " +grams);
- }
- }
Add Comment
Please, Sign In to add comment