我对代码的最后一部分有疑问。我想为特定单词分配数字,但我总是得到 0 值,即使我从第一个 System.out.println 正确获取了这些字符串,我也无法在第二个 System.out.println.Any 获得这些字符串的数字等价物想法如何解决这个问题?
public static double number;
protected void myMethod(HttpServletRequest request, HttpServletResponse response) {
String speech= request.getParameter("speech");
System.out.println("The recognized speech is : "+ speech);
// There is no problem till here.
if(speech == "Hi")
number = 1 ;
if(speech== "Thanks")
number = 2 ;
if(speech== "Bye")
number = 0 ;
System.out.println("The number for the speech is : " + number);
}
但是在这里我没有得到正确的数字,但每个单词只有 0 !