- Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathintegertoroman.java
More file actions
Latest commit
26 lines (26 loc) · 692 Bytes
/
Copy pathintegertoroman.java
File metadata and controls
26 lines (26 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
publicclassIntegerToRoman
{
publicstaticvoidintToRoman(intnum)
{
System.out.println("Integer: " + num);
int[] values = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
String[] romanLetters = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
StringBuilderroman = newStringBuilder();
for(inti=0;i<values.length;i++)
{
while(num >= values[i])
{
num = num - values[i];
roman.append(romanLetters[i]);
}
}
System.out.println("Corresponding Roman Numerals is: " + roman.toString());
}
publicstaticvoidmain(Stringargs[])
{
intToRoman(125);
intToRoman(252);
intToRoman(1000);
intToRoman(1010);
}
}