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