0

EDIT: Sorry about ellipsis that's not what I actually have.

For declaring an array I have something like:

package hearts;

public class pack
{
    String[] values = {"0", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"};
    String[] suits = {"Hearts", "Spades", "Diamonds", "Clubs"}; 

    card[] deck = new card[52]; 

    for (int i = 1; i < 14; i++)
    {
        for (int j = 0; j<4; j++)
        {
            deck[j*13 + i] = new card(suits[j], values[i]);
        }
    }
}

And it keeps telling me Syntax error on token ";", { expected. Does anyone have any ideas what is wrong?

Thanks

3
  • Post your complete code. Commented Feb 5, 2012 at 20:49
  • 1
    @Matt your source looks ok (after edit). Are you sure this is the line that causes the problems ? Commented Feb 5, 2012 at 20:54
  • 1
    This line of code is correct. I think you have an error in the code segment before/after this line. Commented Feb 5, 2012 at 20:55

2 Answers 2

4

The problem is that you have put instructions at the class level. Declare a method and put your instructions there, for example:

public class pack
{
    String[] values = {"0", "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K"};
    String[] suits = {"Hearts", "Spades", "Diamonds", "Clubs"}; 

    public static void main(String[] args) {
        card[] deck = new card[52]; 

        for (int i = 1; i < 14; i++)
        {
            for (int j = 0; j<4; j++)
            {
                deck[j*13 + i] = new card(suits[j], values[i]);
            }
        }
    }
}

Of course, you may put the code into any other method, not necessarily main and not necessarily static.

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

Comments

0

Well of course the compiler complains about the syntax. What's with the ... there ?

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.