程序中是把 字符串形式的数字 转换 为中文读法,需要转换int型的话,可以先使用java.lang.String.valueOf(int i)转为字符串,不支持浮点数的转换。 package com.dapeng.contest1; public class NumberTransfrom { private String[] unms = new String[] { "零","一","二","三","四","五","六","七","八","九" }; private String[] digits = new String[] { "","十","百","千" }; private String[] units = new String[] { "","万","亿","万亿" }; public NumberTransfrom() { } public NumberTransfrom( String[] nums, String[] digits, String[] units ) { this.unms = nums; this.digits = digits; this.units = units; } public void setUnits( String[] units ) { this.units = units; } public void setNums( String[] nums ) { this.unms = nums; } public void setDigits( String[] digits ) { this.digits = digits; } //检查字符串s是否全为数字 public boolean checkIsNumbers( String x ) { if (null == x) { return false; } for( Character c: x.toCharArray() ) { if(c.compareTo('0')<0 || c.compareTo('9')>0) { return false; } } return true; } public String transfrom( String x ) { if( null==x ) { return "您输入的字符串地址为null!"; } if( 0==x.length() ) { return "您输入的字符串长度为0,请输入要转换的数字!"; } if( false==checkIsNumbers(x) ) { return "您输入的字符不都为数字,无法转换!"; } if( x.length()>16 ) { return "您输入的字符串长度大于16