Compare commits

...

1 Commits

Author SHA1 Message Date
e7b18d392c Correction convertion romain vers decimal 2019-06-17 18:54:20 +02:00

View File

@ -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;
}