| 1 | public class IntegerToRoman{ |
| 2 | public static String numberToRoman(int number){//Converts a number into a roman numerial |
| 3 | String roman = ""; |
| 4 | while(number != 0){//checks if the number is not equal to 0, if it is not equal then there is more processing to be done |
| 5 | if(number >= 1000){//if the number is larger than 1000, then add an M to the roman string and subtract 1000 from number |
| 6 | roman += "M"; |
| 7 | number -= 1000; |
| 8 | } |
| 9 | else if(number >= 900){//if the number is larger than 900, then add an CM to the roman string and subtract 900 from number |
| 10 | roman += "CM"; |
| 11 | number -= 900; |
| 12 | } |
| 13 | else if(number >= 500){//if the number is larger than 500, then add an D to the roman string and subtract 500 from number |
| 14 | roman += "D"; |
| 15 | number -= 500; |
| 16 | } |
| 17 | else if(number >= 400){//if the number is larger than 400, then add an CD to the roman string and subtract 400 from number |
| 18 | roman += "CD"; |
| 19 | number -= 400; |
| 20 | } |
| 21 | else if(number >= 100){//if the number is larger than 100, then add an C to the roman string and subtract 100 from number |
| 22 | roman += "C"; |
| 23 | number -= 100; |
| 24 | } |
| 25 | else if(number >= 90){//if the number is larger than 90, then add an XC to the roman string and subtract 90 from number |
| 26 | roman += "XC"; |
| 27 | number -= 90; |
| 28 | } |
| 29 | else if(number >= 50){//if the number is larger than 50, then add an L to the roman string and subtract 50 from number |
| 30 | roman += "L"; |
| 31 | number -= 50; |
| 32 | } |
| 33 | else if(number >= 40){//if the number is larger than 40, then add an XL to the roman string and subtract 40 from number |
| 34 | roman += "XL"; |
| 35 | number -= 40; |
| 36 | } |
| 37 | else if(number >= 10){//if the number is larger than 10, then add an X to the roman string and subtract 10 from number |
| 38 | roman += "X"; |
| 39 | number -= 10; |
| 40 | } |
| 41 | else if(number >= 9){//if the number is larger than 9, then add an IX to the roman string and subtract 9 from number |
| 42 | roman += "IX"; |
| 43 | number -= 9; |
| 44 | } |
| 45 | else if(number >= 5){//if the number is larger than 5, then add an V to the roman string and subtract 5 from number |
| 46 | roman += "V"; |
| 47 | number -= 5; |
| 48 | } |
| 49 | else if(number >= 4){//if the number is larger than 4, then add an IV to the roman string and subtract 4 from number |
| 50 | roman += "IV"; |
| 51 | number -= 4; |
| 52 | } |
| 53 | else if(number >= 1){//if the number is larger than 1, then add an I to the roman string and subtract 1 from number |
| 54 | roman += "I"; |
| 55 | number -= 1; |
| 56 | } |
| 57 | } |
| 58 | return roman; |
| 59 | } |
| 60 | } |
nothing calls this directly
no outgoing calls
no test coverage detected