How do you compare enum to int?
enums, java
Solution
Just use the Enum.ordinal() method of an enum to get the ordered number from 0 to X which you can compare to your `x` variable:
public class Game {
public enum State {
BLANK, // 0
RED, // 1
YELLOW // 2
}
public State getState(int x, int y) {
y = 1;
for (x = 5; x > 0; x--) {
if (x == State.BLANK.ordinal() && y == State.BLANK.ordinal()) {
return State.RED;
}
//return State.BLANK;
}
return State.BLANK;
}
}
Problem
I am trying to change the color by using an enum, I am comparing an enum to an int but it keeps throwing an error ``` public class Game { public enum State{ RED, YELLOW, BLANK; } public State getState(int x, int y) { y=1; for (x=5;x>0;x--) { if (x== BLANK && y== BLANK) { return State.RED; } //return State.BLANK; } return State.BLANK; } ``` How do I compare an int to an enum? so that I can change the color in the first column y which is set to 1