无法访问的语句调用递归方法

tam*_*mir 1 java recursion

编写这段代码时,我尝试编译时会遇到"无法访问的语句"错误,只要我尝试在递归方法中达到[x].

public class recursion
{
public static boolean match (int [] a, int [] pattern)
{
    if(pattern.length==0)
        return true;
    boolean x;
    x=match(a,pattern,0,0);
    if(x==true)
        return true;
    return false;

}

public static boolean match (int [] a, int [] pattern,int aCounter,int ptCounter)
    {
        int count=0;
        int x=aCounter;
        if(x==a.length);
        {
            if(count==pattern.length)
                return true;
            else return false;
        }

        if(a[x]>100)
        {
            count=0;
        return match(a,pattern,aCounter+1,0);
    }
    else if(((pattern[ptCounter]==1)||(pattern[ptCounter]==0))&&((a[x]>-10)&&(a[x]<10)))
    {
        count++;
        return match(a,pattern,aCounter+1,ptCounter+1);
    }
    else if(((pattern[ptCounter]==2)||(pattern[ptCounter]==0))&&(((a[x]<-10)&&(a[x]>-100))||((a[x]>9)&&(a[x]<100))))
    {   
        count++;
        return match(a,pattern,aCounter+1,ptCounter+1);
    }

}

}
Run Code Online (Sandbox Code Playgroud)

将欣赏有关此问题的输入以及关于递归方法的调用.谢谢!

Era*_*ran 6

你的问题是不必要的;:

    if(x==a.length); // here
    {
        if(count==pattern.length)
            return true;
        else return false;
    }
Run Code Online (Sandbox Code Playgroud)

这将;关闭if语句,因此总是执行以下bock(并返回truefalse),并且该块之后的代码变得无法访问.