# 整数转换英文表示

将非负整数 num 转换为其对应的英文表示。

 

示例 1:

输入:num = 123
输出:"One Hundred Twenty Three"

示例 2:

输入:num = 12345
输出:"Twelve Thousand Three Hundred Forty Five"

示例 3:

输入:num = 1234567
输出:"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"

示例 4:

输入:num = 1234567891
输出:"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"

 

提示:

## template ```java class Solution { String[] withinTwentyNum = new String[] { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }; String[] theWholeTen = new String[] { "", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }; String[] unit = new String[] { "", "Thousand", "Million", "Billion" }; public String numberToWords(int num) { if (num == 0) { return withinTwentyNum[num]; } StringBuilder sb = new StringBuilder(); int unitCount = 0; int temp; String[] words = new String[32]; int wordIndex = 0; for (int n = num; num > 0; unitCount++) { n = num % 1000; num /= 1000; if (n == 0) { continue; } words[wordIndex++] = unit[unitCount]; temp = n % 100; if (n % 100 > 0) { if (temp >= 20) { if (temp % 10 > 0) { words[wordIndex++] = withinTwentyNum[temp % 10]; } words[wordIndex++] = theWholeTen[temp / 10]; } else { words[wordIndex++] = withinTwentyNum[temp]; } } temp = n / 100; if (temp > 0) { words[wordIndex++] = "Hundred"; words[wordIndex++] = withinTwentyNum[temp]; } } for (int index = wordIndex - 1; index >= 0; index--) { sb.append(words[index]).append(" "); } return sb.toString().trim(); } } ``` ## 答案 ```java ``` ## 选项 ### A ```java ``` ### B ```java ``` ### C ```java ```