(int num)
| 3 | String[] belowTwenty = { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }; |
| 4 | String[] belowHundred = { "", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; |
| 5 | public String numberToWords(int num) { |
| 6 | if(num==0){ |
| 7 | return "Zero"; |
| 8 | } |
| 9 | if(num<10){ |
| 10 | return belowTen[num]; |
| 11 | } |
| 12 | if(num<20){ |
| 13 | return belowTwenty[num-10]; |
| 14 | } |
| 15 | if(num<100){//74, 70 |
| 16 | return belowHundred[num/10] + (num%10!=0?" " + belowTen[num%10]:""); |
| 17 | } |
| 18 | if(num<1000){ //9 00 |
| 19 | return belowTen[num/100] + " Hundred" + (num%100!=0?" " + numberToWords(num%100):""); |
| 20 | } |
| 21 | if(num<1000000){ //9000 -- 999 000 |
| 22 | return numberToWords(num/1000) + " Thousand" + (num%1000!=0?" " + numberToWords(num%1000):""); |
| 23 | } |
| 24 | if(num<1000000000){ //999 129786 |
| 25 | return numberToWords(num/1000000) + " Million" + (num%1000000!=0?" " + numberToWords(num%1000000):""); |
| 26 | } |
| 27 | return numberToWords(num/1000000000) + " Billion" + (num%1000000000!=0?" " + numberToWords(num%1000000000):""); |
| 28 | } |
| 29 | } |
nothing calls this directly
no outgoing calls
no test coverage detected