Introduction: First of all, lz is a java lovers are currently using java write performance testing tools and scripts, so the great God who has better answer please irrigation!
Title: 1-9999 digital input, an output corresponding to characters, such as one thousand and one output 1001
static void main public (String [] args) {
// digital input
Scanner Scanner new new SC = (the System.in);
System.out.println ( "Please enter a number between 1-9999:");
int COUNT = SC .nextInt ();
System.out.println ( "digital input is:" + COUNT);
// data corresponding database
String [] uint = { "thousand", "hundred", "ten"};
String [] HCOUNT = { "a", "two", "three", "four", "five," "six," "seven," "eight," "nine", "zero"};
the StringBuilder SB = new new the StringBuilder () ;
// number corresponding methods
/ ****
* takes one thousand digital I / 1000 10%
* take hundreds digit I / 100 10%
* takes ten digital I / 10 10%
*% take a 10-bit digital I
* * * /
// output one thousand
if (count / 1000% 10! = 0) {
//System.out.println(hcount[count/1000%10-1]+uint[0]);
sb.append(hcount[count/1000%10-1]+uint[0]);
}
//输出百位
if(count/100%10!=0) {
//System.out.println(hcount[count/100%10-1]+uint[1]);
sb.append(hcount[count/100%10-1]+uint[1]);
}else {
if(sb.length()!=0&&(count/10%10!=0||count%10!=0)) {
sb.append(hcount[9]);
}
}
//输出十位
if(count/10%10!=0) {
//System.out.println(hcount[count/10%10-1]+uint[2]);
sb.append(hcount[count/10%10-1]+uint[2]);
}else {
IF (sb.length ()% 10 = = 0 && COUNT 0!!) {
System.out.println (sb.charAt (sb.length () -. 1));
! IF (sb.indexOf ( "zero") = sb .length () - 1) {// zero to prevent the output of the dual case of nine thousand 9001 2001 and appear
sb.append (HCOUNT [. 9]);
}
}
}
// output bits
if (count% 10 = 0) ! {
//System.out.println(hcount[count%10-1]);
sb.append (HCOUNT [COUNT% 10-1]);
} the else {
// bit is 0 and no digital Qianbaishi
if ( sb.length () == 0) {
sb.append (HCOUNT [. 9]);
}
}
// output
System.out.println (sb.toString ());
}