!Yeet roman int calculation rework

This commit is contained in:
Indyuce 2020-02-13 22:25:42 +01:00
parent 9e4b5fca60
commit 568edef502

View File

@ -94,52 +94,29 @@ public class MMOCoreUtils {
} }
} }
private static final String[] romanChars = { "I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M" };
private static final int[] romanQuantities = { 1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000 };
public static String intToRoman(int input) { public static String intToRoman(int input) {
if (input < 1 || input > 499) if (input < 1)
return "<1";
if (input > 3999)
return ">499"; return ">499";
String s = ""; String result = "";
while (input >= 400) {
s += "CD"; for (int j = 0; j < romanChars.length; j++) {
input -= 400; int i = romanChars.length - j - 1;
int q = romanQuantities[i];
String c = romanChars[i];
while (input >= q) {
result += c;
input -= q;
}
} }
while (input >= 100) {
s += "C"; return result;
input -= 100;
}
while (input >= 90) {
s += "XC";
input -= 90;
}
while (input >= 50) {
s += "L";
input -= 50;
}
while (input >= 40) {
s += "XL";
input -= 40;
}
while (input >= 10) {
s += "X";
input -= 10;
}
while (input >= 9) {
s += "IX";
input -= 9;
}
while (input >= 5) {
s += "V";
input -= 5;
}
while (input >= 4) {
s += "IV";
input -= 4;
}
while (input >= 1) {
s += "I";
input -= 1;
}
return s;
} }
/* /*