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