Created
June 2, 2019 23:03
-
-
Save ardovic/57ce295ed46a8a4f3115f42706b7914e to your computer and use it in GitHub Desktop.
Sample method for converting decimal numbers into roman (Java method)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String integerToRomanConvert(int input){ | |
| if(input < 1 || input > 10000){ | |
| return "Invalid Input"; | |
| } | |
| String s =""; | |
| while(input >= 1000){ | |
| s+="M"; | |
| input -= 1000; | |
| } | |
| while(input >= 900){ | |
| s+="CM"; | |
| input -= 900; | |
| } | |
| while(input >= 500){ | |
| s+="D"; | |
| input -= 500; | |
| } | |
| while(input >= 400){ | |
| s+="CD"; | |
| input -= 400; | |
| } | |
| while(input >= 100){ | |
| s+="C"; | |
| input -= 100; | |
| } | |
| while(input >= 90){ | |
| s+="XC"; | |
| input -= 90; | |
| } | |
| while(input >= 50){ | |
| s+="L"; | |
| input -= 50; | |
| } | |
| while(input >= 40){ | |
| s+="XL"; | |
| input -= 40; | |
| } | |
| while(input >= 10){ | |
| s+="X"; | |
| input -= 10; | |
| } | |
| while(input >= 9){ | |
| s+="IX"; | |
| input -= 9; | |
| } | |
| while(input >= 5){ | |
| s+="V"; | |
| input -= 5; | |
| } | |
| while(input >= 4){ | |
| s+="IV"; | |
| input -= 4; | |
| } | |
| while(input >= 1){ | |
| s+="I"; | |
| input -= 1; | |
| } | |
| return s; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment