私はばかだよ:文字列を含む変数は、 '同じ'文字列でテストに失敗します。どうして?
私のコードは以下のコードです。私はコードを実行し、私の答えとして4を入力します。しかし、その答えは間違っています。私は何を間違えたのですか?助けてくれてありがとう。
import java.io.*;
class class1 {
public static void main (String[] args) throws IOException {
BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
System.out.println("What is the answer to 2 + 2");
String answer;
answer = input.readLine();
if (answer == "4"){
System.out.println("Correct");
} else System.out.println("Incorrect");
}
}
}
しないでくださいをしたい場合accを忘れるept an answer:) – jeff