Can I please have correction to my Code which is giving me false results public
ID: 3584501 • Letter: C
Question
Can I please have correction to my Code which is giving me false results public class RomanNumerals { public String toRoman(int n) { String r = ""; while( n > 0) { if (n>=1000) { r += "M"; n -=1000;n++; } else if( n >= 900) { r += "CM"; n -= 900;n++; } else if( n >= 500) { r += "D"; n -= 500;n++; } else if( n >= 400) { r += "CD"; n -= 400;n++; } else if (n>=100) { r += "C"; n -= 100;n++; } else if (n>=90) { r += "XC"; n -= 90;n++; } else if (n>=50) { r += "L"; n -= 50;n++; } else if (n>=40) { r += "XL"; n -= 40;n++; } else if (n >=10) { r += "X"; n -= 10;n++; } else if (n >=5){ r += "V"; n -= 5 ;n++; }else if (n<=4) { r += "IV"; n -=4; }else if (n>=1) { r += "I"; n -= 1;n++; } } return r; } }Explanation / Answer
Here is your code. Without mistake. You can download it from here
http://pastie.org/5696376
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.