Correction convertion romain vers decimal
This commit is contained in:
parent
b65325911b
commit
e7b18d392c
25
Romain.java
25
Romain.java
@ -9,6 +9,31 @@ public class Romain {
|
||||
}
|
||||
|
||||
public static int convertirEnDecimal(char[] romain) {
|
||||
int cur = 0;
|
||||
int prec = 0;
|
||||
int dec = 0;
|
||||
for (int i = 0; i < romain.length; i++) {
|
||||
prec = cur;
|
||||
cur = asInt(romain[i]);
|
||||
if (prec<cur) {
|
||||
dec -= prec;
|
||||
} else {
|
||||
dec += prec;
|
||||
}
|
||||
}
|
||||
dec+=cur;
|
||||
return dec;
|
||||
}
|
||||
|
||||
public static int asInt(char c) {
|
||||
switch (c) {
|
||||
case 'I':
|
||||
return 1;
|
||||
case 'V':
|
||||
return 5;
|
||||
case 'X':
|
||||
return 10;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user