I keep getting a .class expected error in the if statement. help please.

private int[] hand;
    private int[] play;
public PokerHand(){
          this.hand = new int[5];  
        }
public boolean haveCard(int card){
    if (play[] == card)
        return true;
}
public void displayCards(){
    System.out.println(hand);
}
public void dealCards(){

Recommended Answers

Please post the full text of the error message.

An array element reference requires an index.

Jump to Post

All 2 Replies

Please post the full text of the error message.

An array element reference requires an index.

if (play[] == card)

This line is invalid Java syntax. If you want to check if an int array contains a particular int value, you'll either have to loop over the array to check the occurrence of that value or convert the array to something like a Set (if ordering is not important) and then use its contains method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.