# Moderate 整数打印读法 @CareerCup

package Moderate;

import CtCILibrary.AssortedMethods;

/**
* Given  any  integer, print  an  English  phrase  that  describes  the  integer  (e.g., "One
Thousand, Two Hundred Thirty  Four").

*
*/

public class S17_7 {
public static String[] digits = { "One", "Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine" };
public static String[] teens = { "Eleven", "Twelve", "Thirteen",
"Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen",
"Nineteen" };
public static String[] tens = { "Ten", "Twenty", "Thirty", "Forty",
"Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
public static String[] bigs = { "", "Thousand", "Million" };

public static String numToString(int number) {
if (number == 0) {
return "Zero";
}

if (number < 0) {
return "Negative " + numToString(-1 * number);
}
int count = 0;
String str = "";

while (number > 0) {
if (number % 1000 != 0) {
str = numToString100(number % 1000) + bigs[count] + " " + str;
}
number /= 1000;
count++;
}

return str;
}

public static String numToString100(int number) {
String str = "";

/* Convert hundreds place */
if (number >= 100) {
str += digits[number / 100 - 1] + " Hundred ";
number %= 100;
}

/* Convert tens place */
if (number >= 11 && number <= 19) {
return str + teens[number - 11] + " ";
} else if (number == 10 || number >= 20) {
str += tens[number / 10 - 1] + " ";
number %= 10;
}

/* Convert ones place */
if (number >= 1 && number <= 9) {
str += digits[number - 1] + " ";
}

return str;
}

public static void main(String[] args) {
/* numbers between 100000 and 1000000 */
for (int i = 0; i < 8; i++) {
int value = (int) Math.pow(10, i);
String s = numToString(-1 * value);
System.out.println(-value + ": " + s);
}

/* numbers between 0 and 100 */
for (int i = 0; i < 10; i++) {
int value = AssortedMethods.randomIntInRange(0, 100);
String s = numToString(value);
System.out.println(value + ": " + s);
}

/* numbers between 100 and 1000 */
for (int i = 0; i < 10; i++) {
int value = AssortedMethods.randomIntInRange(100, 1000);
String s = numToString(value);
System.out.println(value + ": " + s);
}

/* numbers between 1000 and 100000 */
for (int i = 0; i < 10; i++) {
int value = AssortedMethods.randomIntInRange(1000, 100000);
String s = numToString(value);
System.out.println(value + ": " + s);
}

/* numbers between 100000 and 1000000 */
for (int i = 0; i < 10; i++) {
int value = AssortedMethods.randomIntInRange(100000, 100000000);
String s = numToString(value);
//			System.out.println(value + ": " + s);
}

/* numbers between 100000 and 1000000 */
for (int i = 0; i < 10; i++) {
int value = AssortedMethods.randomIntInRange(100000000, 1000000000);
String s = numToString(value);
//			System.out.println(value + ": " + s);
}
}
}


## 正整数的中文读法(C++ Python)

• wbcg111
• 2016年04月17日 00:07
• 460

## 华为机试：中文整数读法的拼音转数字

import java.util.*; public class Transfer { public static void main(String[] args) { Map mapint ...

## 将浮点数转换成人民币读法字符串（整数部分在12位以内）

import java.util.Arrays;   import java.util.Scanner; public class Num2Rmb    {        private  S...
• hw_fu
• 2016年11月11日 20:49
• 323

## java 实验七 之 阿拉伯整数转换为中文大写数字（注意读法）

import java.util.*; import java.util.Scanner; public class Lab7 { LinkedList Stack=new LinkedList(...

## A high power moderate band radiator using a switched oscillator

• 2013年01月20日 10:59
• 7.73MB
• 下载

## CareerCup_Top_150_Questions_4th

• 2012年10月19日 14:21
• 2.26MB
• 下载

## Hard 找到由其它单词组成的最长单词 @CareerCup

举报原因： 您举报文章：Moderate 整数打印读法 @CareerCup 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)