Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class UnitConversions
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- double unitTotal = 1;
- double unitLiters = 3.79;
- double unitInches = 2.5;
- double unitKilograms = 0.45359237;
- double unitKilometers = 1.609344;
- System.out.println("Please enter a value:");
- String unitValue = in.nextLine();
- double doubleUnitValue = Double.valueOf(unitValue);
- //System.out.println("Please enter a conversion type: \nGL for Gallons to Liters \nIC for Inches to Centimeters \nPK for Pounds to Kilograms \nMK for Miles to Kilometers");
- //String unitType = in.nextLine();
- //if (unitType == "GL")
- unitTotal = doubleUnitValue * unitLiters;
- System.out.println(doubleUnitValue + " Gallons = " + unitTotal + " Liters.");
- //if (unitType == "IC")
- unitTotal = doubleUnitValue * unitInches;
- //if (unitType == "PK")
- unitTotal = doubleUnitValue * unitKilograms;
- //if (unitType == "MK")
- unitTotal = doubleUnitValue * unitKilometers;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement