if 语句的值始终为空?

Value of if-statement always null?

我正在尝试在 java 到 运行 用户输入字符串的情况下编写一个方法。

代码:

 static String checkWMI(String userVIN){

    String manCountry = null;
    String WMI = userVIN.substring(0, 5);
    String Wcheck = WMI.substring(WMI.length()- 4);

    if(Wcheck.equals("1") || Wcheck.equals("4") || Wcheck.equals("5")) {
         manCountry = "United States";
    }else if(Wcheck.equals("J")){
        manCountry = "Japan";
    }else if(Wcheck.equals("2")){
        manCountry = "Canada";
    }else if(Wcheck.equals("3")){
        manCountry = "Mexico";
    }else if(Wcheck.equals("S")){
        manCountry = "United Kingdom";
    }else if(Wcheck.equals("W")) {
        manCountry = "Germany";
    }

    return manCountry;
}
 }

目标是得到一个特定的子字符串(这样我可以稍后打印出来),然后根据该子字符串的一段确定一个值。我想根据索引为零的字符来决定。当我尝试 运行 这段代码时,只打印“null”,因为它说我的“if 语句总是错误的”。我知道某处一定有逻辑错误,但我找不到。有什么建议吗?

static String checkWMI(String userVIN){

String manCountry = null;
String WMI = userVIN.substring(0, 5);

if(WMI.startsWith("1") || WMI.startsWith("4")  || WMI.startsWith("5") ) {
     manCountry = "United States";
}else if(Wcheck.equals("J")){
    manCountry = "Japan";
}else if(Wcheck.equals("2")){
    manCountry = "Canada";
}else if(Wcheck.equals("3")){
    manCountry = "Mexico";
}else if(Wcheck.equals("S")){
    manCountry = "United Kingdom";
}else if(Wcheck.equals("W")) {
    manCountry = "Germany";
}

return manCountry;

} }

static String checkWMI(String userVIN){

String manCountry = null;
String WMI = userVIN.substring(0, 5);

if(WMI.charAt(0) == "1" || WMI.charAt(0) == "4"  || WMI.charAt(0) == "5"  ) {
     manCountry = "United States";
}else if(Wcheck.equals("J")){
    manCountry = "Japan";
}else if(Wcheck.equals("2")){
    manCountry = "Canada";
}else if(Wcheck.equals("3")){
    manCountry = "Mexico";
}else if(Wcheck.equals("S")){
    manCountry = "United Kingdom";
}else if(Wcheck.equals("W")) {
    manCountry = "Germany";
}

return manCountry;

} }