Java Program Number to Word2025 年 5 月 2 日 | 阅读 11 分钟 在本节中,我们将创建一个 Java 程序,该程序可以将给定的数字转换为单词。例如,如果给定的数字是 54,297,则输出应为 Fifty-Four Thousand Two Hundred Ninety-Seven。让我们为之创建一个Java 程序。 NumberToWordExample1.java 输出 ![]() 数字不限于四位数。那么如果用户输入超过 5 位数的数字怎么办?上述程序不适用于大位数。 将大数字转换为单词转换大数字的逻辑完全不同。让我们看看转换大数字的方法。 NumberToWordExample2.java 输出 ![]() 将非常长的数字转换为单词将非常长的数字转换为单词的逻辑与前一个不同。在继续之前,了解大数字的名称很重要。下表描述了大数字的名称。
让我们创建一个 Java 程序,将非常长的数字转换为单词。 下面的 Java 程序也将负数和小数转换为单词。 NumberToWordExample3.java 输出 0 = zero 4 = four 10 = ten 12 = twelve 100 = one hundred 108 = one hundred eight 299 = two hundred ninety-nine 1000 = one thousand 1003 = one thousand three 2040 = two thousand forty 45213 = forty-five thousand two hundred thirteen 100000 = one hundred thousand 100005 = one hundred thousand five 100010 = one hundred thousand ten 202020 = two hundred two thousand twenty 202022 = two hundred two thousand twenty-two 999999 = nine hundred ninety-nine thousand nine hundred ninety-nine 1000000 = one million 1000001 = one million one 10000000 = ten million 10000007 = ten million seven 99999999 = ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine 9223372036854775807 = nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred seven -9223372036854775808 = minus nine quintillion two hundred twenty-three quadrillion three hundred seventy-two trillion thirty-six billion eight hundred fifty-four million seven hundred seventy-five thousand eight hundred eight 0001.2 = one and two tenth 3.141592 = three and one hundred forty-one thousand five hundred ninety-two millionth 借助上述程序,我们甚至可以转换100位长的数字。 |
我们请求您订阅我们的新闻通讯以获取最新更新。