Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a java program to convert an integer to roman. We have to solve it without loops, which is why I'm trying to figure out
Write a java program to convert an integer to roman. We have to solve it without loops, which is why I'm trying to figure out how to use replace.
I have the following code that I struggle to get working. Please don't send an answer with loops, I already know how to solve it that way.
Fingers crossed, I hope someone can help me out. :)
2 public class RomanNumerals 4 public String getRomanNumber(int number) I 6 return joinC"", nCopies(number, "I")) .replaceC"IIII", "IV") .replaceC"VV", "X") .replaceC"VIV", "IX") .replaceC"XXXXX", "L") .replaceC"XXXX", "XL") replaceC"LL", "C") .replaceC"LXL", "XC") .replaceC"CCCCC", "D") .replaceC"CCCC", "CD" . replace("DD", "M") .replace"DCD", "CM") 7 10 12 13 14 15 16 17 18 19Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started