Frage

I'm pretty new to Java. I'm making a class for a card. The face is the number of the card, and can only be 1-13. I'm trying to validate it by setting f to 1-13. I wanted to simply do this:

public void setFace(int f)
   {

    f int >= 1 && f <= 13);
   }

Obviously, you can't do that. How do would I simply set f to the numbers 1-13? Thanks for any help!

War es hilfreich?

Lösung 2

if (f >= 1 && f <= 13) {
}

Andere Tipps

I would do in this way

public void setFace(int f) {

if(f < 1 || f > 13)
{
   throw new IllegalArgumentException("Invalid face value "+f+" face must be between 1-13");
}
}

Angelo

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top