我的程序在readLine調用後卡住了,if語句不起作用。我究竟做錯了什麼? #java的第一定時器BufferedReader.readLine不起作用
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class nums {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Number Mania!!!");
System.out.println("Pick your favourite number from 1 to 5");
String favNum = br.readLine();
if (favNum=="3"){
System.out.println("Your favourite number is three!");
}
else{
System.out.println("hi!");
}
}
}
另一天,另一個'=='字符串比較...這個問題可能會讓你感興趣:[如何比較Java中的字符串](http://stackoverflow.com/questions/513832/how-doi-i-比較串式的Java)。那麼這也將是有趣的:http://stackoverflow.com/questions/9698260/what-makes-reference-comparison-work-for-some-strings-in-java – Pshemo