Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ConditionalStatementsExcercises;
- import java.util.Scanner;
- public class MetricConvertor {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double sum = Double.parseDouble(scanner.nextLine());
- String input = scanner.nextLine();
- String output = scanner.nextLine();
- if (input.equals("mm")) {
- sum = sum / 1000;
- } else if (input.equals("cm")) {
- sum = sum / 100;
- } else if (input.equals("mi")) {
- sum = sum / 0.000621371192;
- } else if (input.equals("in")) {
- sum = sum / 39.3700787;
- } else if (input.equals("km")) {
- sum = sum / 0.001;
- } else if (input.equals("ft")) {
- sum = sum / 3.2808399;
- } else if (input.equals("yd")) {
- sum = sum / 1.0936133;
- }
- if (output.equals("mm")) {
- sum = sum * 1000;
- } else if (output.equals("cm")) {
- sum = sum * 100;
- } else if (output.equals("mi")) {
- sum = sum * 0.000621371192;
- } else if (output.equals("in")) {
- sum = sum * 39.3700787;
- } else if (output.equals("km")) {
- sum = sum * 0.001;
- } else if (output.equals("ft")) {
- sum = sum * 3.2808399;
- } else if (output.equals("yd")) {
- sum = sum * 1.0936133;
- }
- System.out.printf("%.8f", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement