Answer the question
In order to leave comments, you need to log in
How to add a "-" sign in front of an expression in ENUM?
enum Roman {
O(0), I(1), V(5), X(10), L(50), C(100), -I(-1),- V(-5), -X(-10),- L(-50),- C(-100); // здесь если ввести минусы, то компилятор ругается
static Roman valueOf(int value) {
for (Roman d : Roman.values())
if (value == d.getValue())
return d;
throw new IllegalArgumentException();
}
Roman(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
int value;
}
Answer the question
In order to leave comments, you need to log in
No way.
The enum value is a normal Java identifier and the dash character is not allowed in it.
You can try using underscores instead of dashes.
-V
=> _V
You can look at an enum example for Roman numerals here:
https://stackoverflow.com/questions/3921866/how-do...
Well, write a function that will return a value in a negative value (x *= -1).
Type Roman.V.nagative ()
And that as you want - it is impossible. - this is an arithmetic operator and then a sign that cannot be used in the names of variables and classes.
I would not bother with the function, I would start V (5) and negV (-5)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question