-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo_1.java
More file actions
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
class IntegertoRoman{
public String intToRoman(int num) { // 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"};
StringBuilder result = new StringBuilder(); // MMMMMD
for(int i=0;i<values.length && num > 0;i++){
while(num >= values[i]){
result.append(romans[i]);
num -= values[i];
}
}
return result.toString();
}
}
public class Demo_1{
public static void main(String[] args) {
IntegertoRoman obj = new IntegertoRoman();
String output = obj.intToRoman(97);
System.out.println(output);// 97 - XCVII
}
}