Advertisement
damesova

Metric Convertor

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