Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.     Scanner scanner = new Scanner(System.in);
  9.  
  10.         Double a = Double.parseDouble(scanner.nextLine());
  11.         Double b=a;
  12.         String x = scanner.nextLine();
  13.         String y = scanner.nextLine();
  14.         Double mm =1000.0;
  15.         Double cm = 100.0;
  16.         Double mi = 0.000621371192;
  17.         Double in = 39.3700787;
  18.         Double km = 0.001;
  19.         Double ft = 3.2808399;
  20.         Double yd = 1.0936133;
  21.         Double m  = 1.0;
  22.  
  23.         if (x.equals("mm")) {
  24.             b = a / mm;
  25.         } else if (x.equals("cm")) {
  26.             b = a / cm;
  27.         } else if (x.equals("mi")) {
  28.             b = a / mi ;
  29.  
  30.         }else if (x.equals("in")) {
  31.             b = a / in  ;
  32.         }else if (x.equals("km")) {
  33.             b = a / km  ;
  34.         }else if (x.equals("ft")) {
  35.             b = a / ft   ;
  36.         }else if (x.equals("yd")) {
  37.             b = a / yd    ;
  38.         } else if (x.equals("m")) {
  39.             b = a/m;
  40.         }
  41.  
  42.         if (y.equals("mm")) {
  43.             b = b * mm;
  44.         } else if (y.equals("cm")) {
  45.             b = b * cm;
  46.         } else if (y.equals("mi")) {
  47.             b = b * mi ;
  48.         }else if (y.equals("in")) {
  49.             b = b * in  ;
  50.         }else if (y.equals("km")) {
  51.             b = b * km  ;
  52.         }else if (y.equals("ft")) {
  53.             b = b * ft   ;
  54.         }else if (y.equals("yd")) {
  55.             b = b * yd    ;
  56.         } else if (y.equals("m")) {
  57.             b = b*m;
  58.         }
  59.  
  60.         System.out.printf("%.8f",b);
  61.  
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement