Advertisement
veronikaaa86

[Java] 08. Metric Converter

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