8
          else
    {
        r=Power(s,n-1);
        System.out.println(r);
        int d=r.length;
        char ch=s.charAt(n);
        int v=d+1;
        p[v]=Character.toString(ch);
        String q = p[v];

        for(i=d+2,j=0;i<2d+3,j<d;i++,j++)
        {
            p[i]=r[j].concat(q);
        }
}

A syntax error is shown and var j is not recognized even after declaration... pls help me.

3
  • If a syntax error is shown, then your program cannot run at all. You need to fix the syntax error first. Commented Oct 27, 2012 at 12:18
  • 3
    I don't see the declaration of j; Just place an int j; before the for loop Commented Oct 27, 2012 at 12:18
  • 1
    by the way, i seems to not have been declared either. you might need to change i=d+2 to int i=d+2 Commented Oct 27, 2012 at 12:22

1 Answer 1

22

The problem is the condition of the loop. The correct should be:

for(i=d+2,j=0;i<2d+3 && j<d;i++,j++){ ...

or

for(i=d+2,j=0;i<2d+3 || j<d;i++,j++){ ...

There is no meaning in putting a comma separating two boolean conditions in java.

And as seen in the comments, variables j and i are not declared.

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

1 Comment

Good catch! I can't remember if Java was like C regarding the comma operator, where cond1, cond2 would yield the same result as writing cond2(assuming cond1 has no side-effects, of course, like in this case).

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.