Advertisement
finderabc

MetricConverterFinal

Oct 22nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MetricConverterFinal {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         double amount = Double.parseDouble(scanner.nextLine());
  8.         String input = scanner.nextLine();
  9.         String output = scanner.nextLine();
  10.  
  11.         if("m".equalsIgnoreCase(input)) {
  12.             amount = amount;
  13.         } else if("mm".equalsIgnoreCase(input)){
  14.             amount = amount / 1000;
  15.         } else if("cm".equalsIgnoreCase(input)) {
  16.             amount = amount / 100;
  17.         } else if("mi".equalsIgnoreCase(input)) {
  18.             amount = amount / 0.000621371192;
  19.         } else if("in".equalsIgnoreCase(input)) {
  20.             amount = amount / 39.3700787;
  21.         } else if("km".equalsIgnoreCase(input)) {
  22.             amount = amount / 0.001;
  23.         } else if("ft".equalsIgnoreCase(input)) {
  24.             amount = amount / 3.2808399;
  25.         } else if("yd".equalsIgnoreCase(input)) {
  26.             amount= amount / 1.0936133;
  27.         }
  28.  
  29.         if("m".equalsIgnoreCase(output)) {
  30.             amount = amount;
  31.         } else if("mm".equalsIgnoreCase(output)){
  32.             amount = amount * 1000;
  33.         } else if("cm".equalsIgnoreCase(output)) {
  34.             amount = amount * 100;
  35.         } else if("mi".equalsIgnoreCase(output)) {
  36.             amount = amount * 0.000621371192;
  37.         } else if("in".equalsIgnoreCase(output)) {
  38.             amount = amount * 39.3700787;
  39.         } else if("km".equalsIgnoreCase(output)) {
  40.             amount = amount * 0.001;
  41.         } else if("ft".equalsIgnoreCase(output)) {
  42.             amount = amount * 3.2808399;
  43.         } else if("yd".equalsIgnoreCase(output)) {
  44.             amount= amount * 1.0936133;
  45.         }
  46.  
  47.         System.out.printf("%.8f", amount);
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement