Update IntegerToRoman.java
This commit is contained in:
parent
ec91f0c2ad
commit
c188fa9187
@ -1,19 +1,19 @@
|
|||||||
package Conversions;
|
package Conversions;
|
||||||
|
|
||||||
public class IntegerToRoman {
|
public class IntegerToRoman {
|
||||||
private static int[] allArabianRomanNumbers = new int[] {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
|
private static int[] allArabianRomanNumbers = new int[]{1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
|
||||||
private static String[] allRomanNumbers = new String[] {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
|
private static String[] allRomanNumbers = new String[]{"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
|
||||||
|
|
||||||
public static String integerToRoman(int num) {
|
public static String integerToRoman(int num) {
|
||||||
if(num <= 0) {
|
if (num <= 0) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
for(int a = 0;a < allArabianRomanNumbers.length;a++) {
|
for (int a = 0; a < allArabianRomanNumbers.length; a++) {
|
||||||
int times = num / allArabianRomanNumbers[a];
|
int times = num / allArabianRomanNumbers[a];
|
||||||
for(int b = 0;b < times;b++) {
|
for (int b = 0; b < times; b++) {
|
||||||
builder.append(allRomanNumbers[a]);
|
builder.append(allRomanNumbers[a]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user