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 unitCenti = 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 * unitCenti;
- System.out.println(doubleUnitValue + " Inches = " + unitTotal + " Centimeters.");
- if (unitType != "PK")
- unitTotal = doubleUnitValue * unitKilograms;
- System.out.println(doubleUnitValue + " Pounds = " + unitTotal + " Kilograms.");
- if (unitType != "MK")
- unitTotal = doubleUnitValue * unitKilometers;
- System.out.println(doubleUnitValue + " Miles = " + unitTotal + " Kilometers.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement