Advertisement
katalino

MetricConvertor_2

Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MetricConvertor {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double num = Double.parseDouble(scanner.nextLine());
  8. String from = scanner.nextLine();
  9. String to = scanner.nextLine();
  10.  
  11. double mm = 1000;
  12. double cm = 100;
  13. double mi = 0.000621371192;
  14. double in = 39.3700787;
  15. double km = 0.001;
  16. double ft = 3.2808399;
  17. double yd = 1.0936133;
  18.  
  19.  
  20. if (from == "mm") {
  21. num = num / mm;
  22. }
  23. else if (from == "cm") {
  24. num = num / cm;
  25. }
  26. else if (from == "mi") {
  27. num = num / mi;
  28. }
  29. else if (from == "in") {
  30. num = num / in;
  31. }
  32. else if (from == "km") {
  33. num = num / km;
  34. }
  35. else if (from == "ft") {
  36. num = num / ft;
  37. }
  38. else if (from == "yd") {
  39. num = num / yd;
  40. }
  41.  
  42. if (to == "mm") {
  43. num = num * mm;
  44. }
  45. else if (to == "cm") {
  46. num = num * cm;
  47. }
  48. else if (to == "mi") {
  49. num = num * mi;
  50. }
  51. else if (to == "in") {
  52. num = num * in;
  53. }
  54. else if (to == "km") {
  55. num = num * km;
  56. }
  57. else if (to == "ft") {
  58. num = num * ft;
  59. }
  60. else if (to == "yd") {
  61. num = num * yd;
  62. }
  63.  
  64. System.out.println(num + " " + to);
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement