문제

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!

도움이 되었습니까?

해결책 2

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top