Metric Converter - Java- задача 8
Хора, знае ли някой каква е грешката в този код? Джъдж дава 12/100.
package com.company;
import java.util.Scanner;
public class CMconverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter size: ");
double size = Double.parseDouble(scanner.nextLine());
String sourceMetric = scanner.nextLine();
String destMetric = scanner.nextLine();
if (sourceMetric == "km") {
size = size / 0.001;
}else if (sourceMetric == "cm") {
size = size / 100.0;
}else if (sourceMetric == "mm") {
size = size / 1000.0;
}else if (sourceMetric == "ft") {
size = size / 3.2808399;
}else if (sourceMetric == "yd") {
size = size / 1.0936133;
}else if (sourceMetric == "in") {
size = size / 39.3700787;
}else if (sourceMetric == "mi") {
size = size / 0.000621371192;
}
if (destMetric == "km") {
size = size * 0.001;
}else if (destMetric == "cm") {
size = size * 100.0;
}else if (destMetric == "mm") {
size = size * 1000.0;
}else if (destMetric == "ft") {
size = size * 3.2808399;
}else if (destMetric == "yd") {
size = size * 1.0936133;
}else if (destMetric == "in") {
size = size * 39.3700787;
}else if (destMetric == "mi") {
size = size * 0.000621371192;
}
System.out.println(size + " " + destMetric);
}
}
В този код работи с "==". Някой знае защо?
работи колкото и твоя :Д