SHARE
TWEET

Untitled

a guest Sep 21st, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class MetricConverter {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.         double inputNumber = Double.parseDouble(scan.nextLine());
  8.         String inputMetric = scan.nextLine();
  9.         String outputMetric = scan.nextLine();
  10.  
  11.         switch (inputMetric) {
  12.             case "mm":
  13.                 inputNumber = inputNumber / 1000;
  14.                 break;
  15.             case "cm":
  16.                 inputNumber = inputNumber / 100;
  17.                 break;
  18.             case  "m":
  19.                 break;
  20.         }
  21.         double outNumber = 0;
  22.         switch (outputMetric) {
  23.             case "mm":
  24.                 outNumber = inputNumber * 1000;
  25.                 break;
  26.             case "cm":
  27.                 outNumber = inputNumber * 100;
  28.                 break;
  29.             case "m":
  30.                 outNumber = inputNumber;
  31.                 break;
  32.         }
  33.  
  34.         System.out.printf("%3.f", outNumber);
  35.     }
  36. }
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