我似乎無法找出此代碼中的問題。當我試圖運行它口口聲聲說:解決代碼中的錯誤
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems:
Syntax error, insert "}" to complete MethodBody
Syntax error, insert "}" to complete ClassBody
但是,當我嘗試添加}
的代碼仍然沒有解決的錯誤。
這是代碼:
public String checkPostalCode (String state, int postalno) {
String postalno1 = Integer.toString(postalno);
String result = "";
String BELAIT = "^[3000-3999](1,4}$";
String TUTONG = "^[2600-2618][2900-2920]{1,4}$";
String BANDAR = "^[2000-2599][2619-2898][2921-2999]{1,4}$";
String TEMBURONG = "^[4000-4999]{1,4}$";
if(state == "Belait") {
Pattern chckPostalCode = Pattern.compile(BELAIT);
Matcher chckPostalCodematcher=chckPostalCode.matcher(postalno1);
boolean Belait = chckPostalCodematcher.matches();
if(Belait==true){
result = "pass";
}
else{
result = "fail";
}
if(state == "Tutong") {
Pattern chckPostalCode1 = Pattern.compile(TUTONG);
Matcher chckPostalCodematcher1=chckPostalCode.matcher(postalno1);
boolean Tutong = chckPostalCodematcher.matches();
if(Tutong==true){
result = "pass";
}
else{
result = "fail";
}
if(state == "Bandar Seri Begawan") {
Pattern chckPostalCode2 = Pattern.compile(BANDAR);
Matcher chckPostalCodematcher2=chckPostalCode.matcher(postalno1);
boolean Bandar = chckPostalCodematcher.matches();
if(Bandar==true){
result="pass";
}
else{
result = "fail";
}
if(state == "Temburong") {
Pattern chckPostalCode3 = Pattern.compile(TEMBURONG);
Matcher chckPostalCodematcher3=chckPostalCode.matcher(postalno1);
boolean Temburong = chckPostalCodematcher.matches();
if(Temburong==true){
result="pass";
}
else{
result = "fail";
}
return result;
}
}
return result;
}
}
}))
它只是一個語法錯誤。根據錯誤說明來修復它。你需要一個支架。 –