Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@@ -13,28 +13,70 @@ public class RomanNumeralUtil {
private static final int MIN_VALUE = 1;
private static final int MAX_VALUE = 5999;
//1000-5999
private static final String[] RN_M = {"", "M", "MM", "MMM", "MMMM", "MMMMM"};
private static final String[] RN_M = {
"",
"M",
"MM",
"MMM",
"MMMM",
"MMMMM",
};
//100-900
private static final String[] RN_C = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
private static final String[] RN_C = {
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM",
};
//10-90
private static final String[] RN_X = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
private static final String[] RN_X = {
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC",
};
//1-9
private static final String[] RN_I = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
private static final String[] RN_I = {
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX",
};
public static String generate(int number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
throw new IllegalArgumentException(
String.format(
"The number must be in the range [%d, %d]",
MIN_VALUE,
MAX_VALUE
)
String.format(
"The number must be in the range [%d, %d]",
MIN_VALUE,
MAX_VALUE
)
);
}
return RN_M[number / 1000]
+ RN_C[number % 1000 / 100]
+ RN_X[number % 100 / 10]
+ RN_I[number % 10];
return (
RN_M[number / 1000] +
RN_C[number % 1000 / 100] +
RN_X[number % 100 / 10] +
RN_I[number % 10]
);
}
}