- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo_1.java
More file actions
Latest commit
23 lines (21 loc) · 753 Bytes
/
Copy pathDemo_1.java
File metadata and controls
23 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
classIntegertoRoman{
publicStringintToRoman(intnum) { // 55 - DLV
int[] values = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] romans = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
StringBuilderresult = newStringBuilder(); // MMMMMD
for(inti=0;i<values.length && num > 0;i++){
while(num >= values[i]){
result.append(romans[i]);
num -= values[i];
}
}
returnresult.toString();
}
}
publicclassDemo_1{
publicstaticvoidmain(String[] args) {
IntegertoRomanobj = newIntegertoRoman();
Stringoutput = obj.intToRoman(97);
System.out.println(output);// 97 - XCVII
}
}