将字符串的数字转换为大写
package lianxi.biancheng.test;import java.util.Scanner;
public class T5 {
public void way1(char m) {
if (m == '1')
System.out.print("壹");
else if (m == '2')
System.out.print("贰");
else if (m == '3')
System.out.print("叁");
else if (m == '4')
System.out.print("肆");
else if (m == '5')
System.out.print("伍");
else if (m == '6')
System.out.print("陆");
else if (m == '7')
System.out.print("柒");
else if (m == '8')
System.out.print("捌");
else if (m == '9')
System.out.print("玖");
}
public void way2() {
System.out.print("零");
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("请输入小于等于7的数:");
String a = s.nextLine();
String b = a.trim();
char[] ch = null;
ch = b.toCharArray();
T5 p = new T5();
if (ch.length == 1) {
if (ch[0] != '0')
p.way1(ch[0]);
else
p.way2();
}
if (ch.length == 2) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("拾");
if (ch[1] != '0')
p.way1(ch[1]);
}
}
if (ch.length == 3) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("佰");
if (ch[1] != '0') {
p.way1(ch[1]);
System.out.print("拾");
if (ch[2] != '0') {
p.way1(ch[2]);
}
} else {
if (ch[2] != '0') {
p.way2();
p.way1(ch[2]);
}
}
}
}
if (ch.length == 4) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("千");
if (ch[1] != '0') {
p.way1(ch[1]);
System.out.print("佰");
if (ch[2] != '0') {
p.way1(ch[2]);
System.out.print("拾");
if (ch[3] != '0') {
p.way1(ch[3]);
}
} else {
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
}
}
} else {
if (ch[2] != '0') {
p.way2();
p.way1(ch[2]);
System.out.print("拾");
if (ch[3] != '0') {
p.way1(ch[3]);
}
} else {
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
}
}
}
}
}
if (ch.length == 5) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("万");
if (ch[1] != '0') {
p.way1(ch[1]);
System.out.print("千");
if (ch[2] != '0') {
p.way1(ch[2]);
System.out.print("佰");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("拾");
if (ch[4] != 0)
p.way1(ch[4]);
} else {
if (ch[4] != '0')
p.way2();
p.way1(ch[4]);
}
} else {
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
System.out.print("拾");
if (ch[4] != '0')
p.way1(ch[4]);
}
}
} else {
if (ch[2] != '0') {
p.way2();
p.way1(ch[2]);
System.out.print("佰");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("拾");
if (ch[4] != '0') {
p.way1(ch[4]);
}
} else {
if (ch[4] != '0')
p.way2();
p.way1(ch[4]);
}
} else {
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
System.out.print("拾");
if (ch[4] != '0')
p.way1(ch[4]);
} else {
if (ch[4] != '0')
p.way2();
p.way1(ch[4]);
}
}
}
}
}
if (ch.length == 6) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("拾");
if (ch[1] != '0') {
p.way1(ch[1]);
System.out.print("万");
if (ch[2] != '0') {
p.way1(ch[2]);
System.out.print("千");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("佰");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0')
p.way1(ch[5]);
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
} else {
if (ch[4] != '0') {
p.way2();
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0')
p.way1(ch[5]);
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
}
} else {// ,万位不等于0,千位上等于0
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
System.out.print("佰");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0') {
p.way1(ch[5]);
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
} else {
if (ch[4] != '0') {
p.way2();
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0') {
p.way1(ch[5]);
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
}
}
} else {// 万位上为0
System.out.print("万");
if (ch[2] != '0') {
p.way1(ch[2]);
System.out.print("千");
} else {// 万位千位都为0
if (ch[3] != '0') {
p.way2();
p.way1(ch[3]);
System.out.print("佰");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0') {
p.way1(ch[5]);
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
} else {// 万千百位都为0
if (ch[4] != '0') {
p.way2();
p.way1(ch[4]);
System.out.print("拾");
if (ch[5] != '0') {
p.way1(ch[5]);
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
}
}
}
}
}
}
}
if (ch.length == 7) {
if (ch[0] != '0') {
p.way1(ch[0]);
System.out.print("佰");
if (ch[1] != '0') {
p.way1(ch[1]);
System.out.print("拾");
if (ch[2] != '0') {
p.way1(ch[2]);
System.out.print("万");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("千");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("佰");
if (ch[5] != '0') {
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
}
}
} else {
System.out.print("万");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("千");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("佰");
if (ch[5] != '0') {
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
}
}
}
} else {
if (ch[2] != '0') {
p.way2();
p.way1(ch[2]);
System.out.print("万");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("千");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("佰");
if (ch[5] != '0') {
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
}
}
} else {
if (ch[3] != '0') {
System.out.print("万");
if (ch[3] != '0') {
p.way1(ch[3]);
System.out.print("千");
if (ch[4] != '0') {
p.way1(ch[4]);
System.out.print("佰");
if (ch[5] != '0') {
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
} else {
if (ch[5] != '0') {
p.way2();
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
}
}
} else {
if (ch[4] != '0') {
System.out.print("万");
p.way2();
p.way1(ch[4]);
System.out.print("佰");
if (ch[5] != '0') {
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
p.way2();
p.way1(ch[6]);
}
}
} else {
if (ch[5] != '0') {
System.out.print("万");
p.way2();
p.way1(ch[5]);
System.out.print("拾");
if (ch[6] != '0')
p.way1(ch[6]);
} else {
if (ch[6] != '0') {
System.out.print("万");
p.way2();
p.way1(ch[6]);
} else
System.out.print("万");
}
}
}
}
}
}
}
}
}