62,614
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
public class Change {
/**
* @param args
*/
long e;
int FirstDigit;
int SecondDigit;
int ThirdDigit;
int FourthDigit;
int FifthDigit;
int Digit;
public Change (long e){
this.e = e;
}
public String GargeDigit(){
String a5,a4,a3,a2,a1;
Contain a = new Contain();
if(e/100000>0)
{ String g = "错误,数字必须小于十万";
return g;
}
else if (e/10000>0) {
FirstDigit = (int)e/10000;
SecondDigit = (int)((e/1000)%10);
ThirdDigit = (int)((e/100)%10);
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit = 5;
if (FirstDigit != 0) a5 = String.valueOf(FirstDigit);
else a5= "";
if (SecondDigit != 0) a4 = String.valueOf(SecondDigit);
else a4 = "";
if (ThirdDigit != 0) a3 = String.valueOf(ThirdDigit);
else a3 = "";
if(FourthDigit != 0) a2 = String.valueOf(FourthDigit);
else a2 = "";
a1 = String.valueOf(FifthDigit);
String result = a.map2.get(a5) + a.map1.get("1") + a.map2.get(a4) + a.map1.get("2") + a.map2.get(a3) + a.map1.get("3")+ a.map2.get(a2) + a.map1.get("4") + a.map2.get(a1);
return result;
}
else return "a";
/* else if (e/1000>0) {
FirstDigit = 0;
SecondDigit = (int)e/1000;
ThirdDigit = (int)(e/100)%10;
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit = 4;
}
else if (e/100>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit =(int)e/100;
FourthDigit = (int) ((e/10)%10);
FifthDigit = (int) ((e/1)%10);
Digit =3;
}
else if (e/10>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit = 0;
FourthDigit =(int)e/100;
FifthDigit = (int) ((e/1)%10);
Digit =2;
}
else if (e>0) {
FirstDigit = 0;
SecondDigit = 0;
ThirdDigit = 0;
FourthDigit = 0;
FifthDigit = (int) ((e/1)%10);
Digit =1;
}*/
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Change a = new Change(75432);
System.out.println(a.GargeDigit());
System.out.println("Digit = " + a.Digit);
System.out.println("FirstDigit = " + a.FirstDigit);
System.out.println("SecondDigit = " + a.SecondDigit);
System.out.println("ThirdDigit = " + a.ThirdDigit);
System.out.println("FourthDigit = " + a.FourthDigit);
System.out.println("FifthDigit = " + a.FifthDigit);
}
}
class Contain{
Map<String,String> map1 = new HashMap<String,String>();
Map<String,String> map2 = new HashMap<String,String>();
public Contain(){
map1.put("1", "万");
map1.put("2", "千");
map1.put("3", "百");
map1.put("4", "十");
map1.put("", "");
map2.put("1", "壹");
map2.put("2", "貳");
map2.put("3", "叁");
map2.put("4", "肆");
map2.put("5", "伍");
map2.put("6", "陆");
map2.put("7", "柒");
map2.put("8", "捌");
map2.put("9", "玖");
map2.put("0", "");
}
}
// 只能输入5位数
// 第一个问题 当50000的时候 千百十也有输出
// 第二个问题 当50001的时候 输出不对
/*
我自己写的 还有很多很多bug LZ跟我一起优化下好吗