forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerNumberToRomanNumeral.java
More file actions
32 lines (25 loc) · 967 Bytes
/
IntegerNumberToRomanNumeral.java
File metadata and controls
32 lines (25 loc) · 967 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
27
28
29
30
31
32
public class IntegerToRoman {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int n=s.nextInt();
String answer= IntegerToRoman(n);
System.out.println(answer);
}
public static String IntegerToRoman(int num)
{
String m[] = {"", "M", "MM", "MMM"};
String c[] = {"", "C", "CC", "CCC", "CD", "D",
"DC", "DCC", "DCCC", "CM"};
String x[] = {"", "X", "XX", "XXX", "XL", "L",
"LX", "LXX", "LXXX", "XC"};
String i[] = {"", "I", "II", "III", "IV", "V",
"VI", "VII", "VIII", "IX"};
String thousands = m[num/1000];
String hundereds = c[(num%1000)/100];
String tens = x[(num%100)/10];
String ones = i[num%10];
String ans = thousands + hundereds + tens + ones;
return ans;
}
}