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;
}
}
 }))
1
  • It just a syntax error. Fix it according to what the error says. You need a bracket somewhere. Commented Nov 9, 2013 at 15:18

1 Answer 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.