Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Integer To Roman Problem Solution in Java #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Java/Integer to Roman/IntegerToRoman.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.LinkedHashMap;
import java.util.Scanner;

public class IntegerToRoman {
public static void main(String args[]) {
String ans = "";
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
LinkedHashMap<Integer, String> map = new LinkedHashMap<>();

map.put(1000, "M");
map.put(900, "CM");
map.put(500, "D");
map.put(400, "CD");
map.put(100, "C");
map.put(90, "XC");
map.put(50, "L");
map.put(40, "XL");
map.put(10, "X");
map.put(9, "IX");
map.put(5, "V");
map.put(4, "IV");
map.put(1, "I");

while (num > 0) {
for (int i : map.keySet()) {
if (num >= i) {
ans += map.get(i);
num -= i;
break;
}
}
}
System.out.println("Result: " + ans);
}
}