forked from joharbatta/DataStructure-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintToRoman.java
More file actions
26 lines (21 loc) · 807 Bytes
/
intToRoman.java
File metadata and controls
26 lines (21 loc) · 807 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
import java.util.*;
public class intToRoman {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
romanNumeral(n);
}
static void romanNumeral(int num) {
String thousands[] = {"", "M", "MM", "MMM"};
String hundreds[] = {"", "C", "CC", "CCC", "CD", "D",
"DC", "DCC", "DCCC", "CM"};
String tens[] = {"", "X", "XX", "XXX", "XL", "L",
"LX", "LXX", "LXXX", "XC"};
String ones[] = {"", "I", "II", "III", "IV", "V",
"VI", "VII", "VIII", "IX"};
System.out.print(thousands[num/1000]);
System.out.print(hundreds[(num%1000)/100]);
System.out.print(tens[(num%100)/10]);
System.out.print(ones[num%10]);
}
}