yovkovbpfps

Conditional Statement Metric Converter

May 1st, 2019
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class sa {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. double value = Double.parseDouble(scanner.nextLine());
  7. String inputMetric = scanner.nextLine();
  8. String outMetric = scanner.nextLine();
  9.  
  10. if (inputMetric.equals("m")) {
  11. value /= 1;
  12. } else if (inputMetric.equals("cm")) {
  13. value /= 100;
  14. } else if (inputMetric.equals("mm")) {
  15. value /= 1000;
  16. }
  17.  
  18. if (outMetric.equals("m")) {
  19. value *= 1;
  20. } else if (outMetric.equals("cm")) {
  21. value *= 100;
  22. } else if (outMetric.equals("mm")){
  23. value *= 1000;
  24. }
  25. System.out.printf("%.3f", value);
  26. }
  27. }
Add Comment
Please, Sign In to add comment