Java 問題 ~~~~

2006-11-07 4:48 am
String tmp, carType = "";
tmp = JOptionPane.showInputDialog("Please input car type (CB/T) : ");
if (tmp == "C")
{carType = "Car";
  System.out.print("AAAAAAAAAA");}
else if (tmp == "T")
 {carType = "Truck";}
else if (tmp == "B")
 {carType = "Bus";}
點解輸入"C"個陣,無出"AAAAAAAAAA",
2個既資料形態唔係都係String 咩?
點攪?

回答 (1)

2006-11-07 4:59 am
✔ 最佳答案
因為這是String
String是object, 不能用 == 比較

你應用 String的其中一個method - equals()

if(tmp.equals("Car"))
{
...
}


收錄日期: 2021-04-12 18:12:09
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061106000051KK04114

檢視 Wayback Machine 備份