Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Locale;
- import java.util.Map;
- import java.util.Scanner;
- public class UnitMeasureConverter {
- public static void main(String[] args) {
- Locale.setDefault(new Locale("us", "Us"));
- Scanner console = new Scanner(System.in);
- Map<String, Double> map1map = new HashMap<String, Double>();
- map1map.put("m", 1d);
- map1map.put("mm", 1000d);
- map1map.put("cm", 100d);
- map1map.put("in", 39.3700787d);
- map1map.put("km", 0.001d);
- map1map.put("ft", 3.2808399d);
- map1map.put("yd", 1.0936133d);
- map1map.put("mi", 0.000621371192d);
- Double input = Double.parseDouble(console.nextLine());
- String firstType = console.nextLine();
- String secondType = console.nextLine();
- Double value1 = map1map.get(firstType);
- Double value2 = map1map.get(secondType);
- Double result = (input / value1) * value2;
- System.out.printf("%.8f " + secondType, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement