0

I cant seem to figure out the problem in this code. when i tried running it keeps on saying :

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problems: 
    Syntax error, insert "}" to complete MethodBody
    Syntax error, insert "}" to complete ClassBody

But when i tried adding } to the code it still doesn't resolve the error.

This is the code:

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;
}
}
 }))
4

1 回答 1

1

You have forgot to close braces here:

if(Belait==true){
    result = "pass";
} // you forgot this

Same applies for if(Tutong==true) , if(Bandar==true) etc.

Always use IDEs to avoid these type of typos.

于 2013-11-09T15:19:05.593 回答