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