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);
}
}
String a = "1";
String b =a;
b = "1";
b == a // true
Моя грешка
я пробвай с
b = new String("1");
Вместо
b = "1";
:)
https://i.stack.imgur.com/71l1O.jpg