SHARE
TWEET

Untitled

a guest Sep 4th, 2017 145 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.  
  9.         public static void main(String[] args) {
  10.             Scanner input = new Scanner(System.in);
  11.  
  12.             BigDecimal size = input.nextBigDecimal();
  13.             String sourceMetric = input.next().toLowerCase();
  14.             String destinationMetric = input.next().toLowerCase();
  15.  
  16.             if (sourceMetric.equals("km")) size = size.divide(new BigDecimal("0.001"),5,BigDecimal.ROUND_DOWN);
  17.             if (sourceMetric.equals("mm")) size = size.divide(new BigDecimal("1000"),5,BigDecimal.ROUND_DOWN);
  18.             if (sourceMetric.equals("cm")) size = size.divide(new BigDecimal("100"),5,BigDecimal.ROUND_DOWN);
  19.             if (sourceMetric.equals("mi")) size = size.divide(new BigDecimal("0.000621371192"),5,BigDecimal.ROUND_DOWN);
  20.             if (sourceMetric.equals("in")) size = size.divide(new BigDecimal("39.3700787"),5,BigDecimal.ROUND_DOWN);
  21.             if (sourceMetric.equals("ft")) size = size.divide(new BigDecimal("3.2808399"),5,BigDecimal.ROUND_DOWN);
  22.             if (sourceMetric.equals("yd")) size = size.divide(new BigDecimal("1.0936133"),5,BigDecimal.ROUND_DOWN);
  23.             if (destinationMetric.equals("km")) size = size.multiply(new BigDecimal("0.001"));
  24.             if (destinationMetric.equals("mm")) size = size.multiply(new BigDecimal("1000"));
  25.             if (destinationMetric.equals("cm")) size = size.multiply(new BigDecimal("100"));
  26.             if (destinationMetric.equals("mi")) size = size.multiply(new BigDecimal("0.000621371192"));
  27.             if (destinationMetric.equals("in")) size = size.multiply(new BigDecimal("39.3700787"));
  28.             if (destinationMetric.equals("ft")) size = size.multiply(new BigDecimal("3.2808399"));
  29.             if (destinationMetric.equals("yd")) size = size.multiply(new BigDecimal("1.0936133"));
  30.             System.out.println(size + " " + destinationMetric);
  31.         }
  32.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top