package trs.lyj.web;
imp
ort java.util.Scanner; public class RMB {
private static String[] shuju = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒",
"捌", "玖" };public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String rmb = changetext(scan.nextLine());// 可以成功返回一批数据,但是还有些欠缺,主要是不符合我们的习惯System.out.println(rmb);
}private static String changetext(String nextLine) {
String str = "";
if (nextLine.startsWith("0") || nextLine.length() > 12) {
System.out.println("数据不合法");
}
nextLine = nextLine.replaceAll("\\s+", "");
if (nextLine.contains(".")) {
String[] line = nextLine.split("\\.");
nextLine = line[0];
int value = Integer.parseInt(line[1].substring(0, 2));
str = shuju[value / 10] + "角" + shuju[value % 10] + "分";
}
// System.out.println(nextLine);
String[] shuju2 = new String[(nextLine.length() % 4 == 0) ? (nextLine
.length() / 4) : (nextLine.length() / 4) + 1];// 定义数段数组的大小
int j = 0;
if (nextLine.length() % 4 != 0) {
shuju2[j] = nextLine.substring(0, nextLine.length() % 4);// 第一组数据
int a = nextLine.length() % 4;
for (int i = 1; i < shuju2.length; i++) {
shuju2[i] = nextLine.substring(a, a + 4);
a = a + 4;
}
} else {
for (int i = 0; i < shuju2.length; i++) {
shuju2[i] = nextLine.substring(j, j + 4);
j = j + 4;
}
}System.out.println(shuju2.length);// 新数组长度
// 到此为止正常
String restr = "";
if (shuju2.length == 3) {
restr += parseShuju(shuju2[0]) + "亿" + parseShuju(shuju2[1]) + "万"
+ parseShuju(shuju2[2]) + "圆";
}
if (shuju2.length == 2) {
restr += parseShuju(shuju2[0]) + "万" + parseShuju(shuju2[1]) + "圆";
}
if (shuju2.length == 1) {restr += parseShuju(shuju2[0]) + "圆";
}
return restr + str;
}public static String parseShuju(String shu) {
int line = Integer.parseInt(shu);
int qian = line / 1000;
int bai = (line % 1000) / 100;
int shi = (line % 100) / 10;
int ge = line % 10;
String ssh = "";
if (qian != 0) {
ssh += shuju[qian] + "仟";
}
if (bai != 0) {
ssh += shuju[bai] + "佰";
}else if(qian!=0&&bai==0){
ssh+="零";
}
if (shi != 0) {
ssh += shuju[shi] + "拾";
}
if (ge != 0) {
ssh += shuju[ge];
}
// ssh=shuju[qian]+"仟"+shuju[bai]+"佰"+shuju[shi]+"拾"+shuju[ge];
return ssh;
}}
该程序对零的处理存在问题,基本就是没有处理,希望高人们给点意见。