如何检查 countryName 和 capitalName 实例变量是否都以大写字母开头?我确定我必须使用涉及诸如“^ [AZ]”之类的正则表达式,但不确定如何或在何处放置完整代码。我是 java 的初学者,如果有任何帮助或建议,我将不胜感激。
java.util.regex.*;
public class CountryInfo {
private String countryName;
private String capitalName;
public CountryInfo (String countryName, String capitalName) {
super();
this.countryName=countryName;
this.capitalName=capitalName;
}
public String getCountryName() {
return countryName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String getCapitalName() {
return capitalName;
}
public void setCapitalName(String capitalName) {
this.capitalName = capitalName;
}
}