public class Change1 { public String change(String integer, String decimal) { String output = new String(); String output1 = new String(); String output2 = new String(); String temp1 = new String(); //String temp2=" "; output1 = tochinese(integer.toCharArray()); int j = 0,k=0; k=output1.length(); for (int i = k; i > 0; i--) { temp1 = output1.substring(i-1, i); /**if(temp1.equals("零")) { if(temp1.equals(temp2)){ temp2=temp1; temp1="";} else { temp2=temp1; if(i==k)temp1=""; } System.out.println(temp1); } else { temp2=" "; */ switch (j%4) { case 0: break; case 1: temp1 += "拾"; break; case 2: temp1 += "佰"; break; case 3: temp1 +="仟"; break; } if (j==4||j==12) temp1 += "万"; if (j==8) temp1 += "亿"; output = temp1 + output; j++; } output+=" "+" "+" "; System.out.println(output); int s=0; String dx=""; while(s<=(output.length()-3)) { if(!output.substring(s,s+1).equals("零"))//不为零 { dx+=output.substring(s,s+2); s=s+2; } else//为零有两种情况 { if(output.substring(s+1,s+2).equals("亿")||output.substring(s+1,s+2).equals("万"))//零后边是亿或万又有两种情况 { if(!dx.substring(dx.length()-1,dx.length()).equals("亿"))//亿和不万相邻时显示万 { dx+=output.substring(s+1,s+2); s=s+2; } else { s=s+2; } } else//零后边不是亿或万又有两种情况 { if(!output.substring(s+2,s+3).equals("零"))//下一个数字不为零时,显示零 { dx+=output.substring(s,s+1); s=s+2; } else//为零时,去掉零 { s=s+2; System.out.println(dx); } } } } dx=dx.trim(); if(dx.substring(dx.length()-1,dx.length()).equals("零")){dx=dx.substring(0,dx.length()-1);} if (decimal != null) { output2 = tochinese(decimal.toCharArray()); return dx + "圆" + output2.substring(0,1)+"角"+output2.substring(1,2)+"分"; } return dx+"圆"+"整"; }
public String tochinese(char[] temp) { String chinese = new String(); String output = new String(); for (int i = 0; i < temp.length; i++) { switch (temp[i]) { case '1': chinese = "壹"; break; case '2': chinese = "贰"; break; case '3': chinese = "叁"; break; case '4': chinese = "肆"; break; case '5': chinese = "伍"; break; case '6': chinese = "陆"; break; case '7': chinese = "柒"; break; case '8': chinese = "捌"; break; case '9': chinese = "玖"; break; case '0': chinese = "零"; break; } output += chinese; } return output; } public static void main(String[] args) { Change1 dx1=new Change1(); String s = args[0]; try { Float.parseFloat(s); } catch (Exception e) { e.printStackTrace(); } String dx; if (s.indexOf(".") > 0) { String integer = s.substring(0, s.indexOf(".")); String decimal = s.substring(s.indexOf(".")+1, s.length()); dx = dx1.change(integer, decimal); } else { dx = dx1.change(s, null); } //String chinese = new String(output.getBytes("ISO8859-1"), "GBK"); System.out.println("number:"+s); System.out.println("chinese:"+dx); }
public class Test { static String moneyD =new String(); static String moneyBefore=new String() ; static String moneyAfter=new String(); static StringBuffer moneyA = new StringBuffer(); public static String getTurns(int i) { switch (i) { case 2 : moneyD = "拾"; break; case 3 : moneyD = "佰"; break; case 4 : moneyD = "仟"; break; case 5 : moneyD = "万"; break; case 6 : moneyD = "拾"; break; case 7 : moneyD = "佰"; break; case 8 : moneyD = "仟"; break; case 9 : moneyD = "亿"; break; case 10 : moneyD = "拾"; break; case 11 : moneyD = "佰"; break; case 12 : moneyD = "仟"; break; } return moneyD.toString(); } public static String getTurnMoneyWord(String s) { switch (Integer.parseInt(s)) { case 0 : return "零"; case 1 : return "壹"; case 2 : return "贰"; case 3 : return "叁"; case 4 : return "肆"; case 5 : return "伍"; case 6 : return "陆"; case 7 : return "柒"; case 8 : return "捌"; } return "玖"; } public static String getTurnMoneys(String money) { try { if (money.indexOf("-") != -1) { moneyA.append("负"); money = money.substring(money.indexOf("-") + 1, money.length()); } if (money.indexOf(".") != -1) { moneyBefore= money.substring(0, money.indexOf(".")); moneyAfter = money.substring(money.indexOf(".") + 1, money.length()); } else { moneyBefore = money; moneyAfter = "none"; } if (moneyBefore.length() == 1&& moneyBefore.charAt(0) == '0'&& moneyAfter == "none") { moneyA.append("零"); moneyA.append("圆"); } else { for (int i = 0; i < moneyBefore.length(); i++) { if (moneyBefore.charAt(i) != '0') { moneyA.append(getTurnMoneyWord( String.valueOf( String.valueOf(moneyBefore.charAt(i))).concat(""))); if (moneyBefore.length() != i + 1) moneyA.append(getTurns(moneyBefore.length() - i)); continue; } if (moneyBefore.length() - i == 5&&( moneyBefore.length() > 5&& moneyBefore.length() <= 9)) moneyA.append("万"); if (moneyBefore.length() - i == 9&& moneyBefore.length() > 9) moneyA.append("亿"); if (moneyBefore.length() != i + 1&& moneyBefore.charAt(i + 1) != '0') moneyA.append("零"); } if (moneyBefore.length() != 1 || moneyBefore.charAt(0) != '0') { moneyA.append("圆"); } } if (!moneyAfter.equals("none")) { for (int i = 0; i < moneyAfter.length(); i++) { if (i == 0) if (moneyAfter.charAt(i) != '0') { moneyA.append(getTurnMoneyWord(String.valueOf( String.valueOf( moneyAfter.charAt(i))).concat(""))); moneyA.append("角"); } else if (moneyBefore.charAt(0) != '0' && moneyAfter.length()>1 && (!moneyAfter.equals("00"))) moneyA.append("零"); if (i == 1 && moneyAfter.charAt(i) != '0') { moneyA.append(getTurnMoneyWord(String.valueOf( String.valueOf(moneyAfter.charAt(i))).concat( ""))); moneyA.append("分"); } } } if (moneyAfter.equals("none") || moneyAfter.length() != 2 || moneyAfter.equals("00")) moneyA.append("整"); } catch (Exception exception) { } return moneyA.toString(); } public static void main(String str[]) throws IOException{ //double d=2302.6; // String s= Double.toString(d); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); String ss=getTurnMoneys(s); System.out.println(ss); } }
{
public String change(String integer, String decimal)
{
String output = new String();
String output1 = new String();
String output2 = new String();
String temp1 = new String();
//String temp2=" ";
output1 = tochinese(integer.toCharArray());
int j = 0,k=0;
k=output1.length();
for (int i = k; i > 0; i--)
{
temp1 = output1.substring(i-1, i);
/**if(temp1.equals("零"))
{
if(temp1.equals(temp2)){
temp2=temp1;
temp1="";}
else {
temp2=temp1;
if(i==k)temp1="";
}
System.out.println(temp1);
}
else
{
temp2=" ";
*/
switch (j%4)
{
case 0:
break;
case 1:
temp1 += "拾";
break;
case 2:
temp1 += "佰";
break;
case 3:
temp1 +="仟";
break;
}
if (j==4||j==12)
temp1 += "万";
if (j==8)
temp1 += "亿";
output = temp1 + output;
j++;
}
output+=" "+" "+" ";
System.out.println(output);
int s=0;
String dx="";
while(s<=(output.length()-3))
{
if(!output.substring(s,s+1).equals("零"))//不为零
{
dx+=output.substring(s,s+2);
s=s+2;
}
else//为零有两种情况
{
if(output.substring(s+1,s+2).equals("亿")||output.substring(s+1,s+2).equals("万"))//零后边是亿或万又有两种情况
{
if(!dx.substring(dx.length()-1,dx.length()).equals("亿"))//亿和不万相邻时显示万
{
dx+=output.substring(s+1,s+2);
s=s+2;
}
else
{
s=s+2;
}
}
else//零后边不是亿或万又有两种情况
{
if(!output.substring(s+2,s+3).equals("零"))//下一个数字不为零时,显示零
{
dx+=output.substring(s,s+1);
s=s+2;
}
else//为零时,去掉零
{
s=s+2;
System.out.println(dx);
}
}
}
}
dx=dx.trim();
if(dx.substring(dx.length()-1,dx.length()).equals("零")){dx=dx.substring(0,dx.length()-1);}
if (decimal != null)
{
output2 = tochinese(decimal.toCharArray());
return dx + "圆" + output2.substring(0,1)+"角"+output2.substring(1,2)+"分";
}
return dx+"圆"+"整";
}
{
String chinese = new String();
String output = new String();
for (int i = 0; i < temp.length; i++)
{
switch (temp[i])
{
case '1':
chinese = "壹";
break;
case '2':
chinese = "贰";
break;
case '3':
chinese = "叁";
break;
case '4':
chinese = "肆";
break;
case '5':
chinese = "伍";
break;
case '6':
chinese = "陆";
break;
case '7':
chinese = "柒";
break;
case '8':
chinese = "捌";
break;
case '9':
chinese = "玖";
break;
case '0':
chinese = "零";
break;
}
output += chinese;
}
return output;
}
public static void main(String[] args)
{
Change1 dx1=new Change1();
String s = args[0];
try
{
Float.parseFloat(s);
}
catch (Exception e)
{
e.printStackTrace();
}
String dx;
if (s.indexOf(".") > 0)
{
String integer = s.substring(0, s.indexOf("."));
String decimal = s.substring(s.indexOf(".")+1, s.length());
dx = dx1.change(integer, decimal);
}
else
{
dx = dx1.change(s, null);
}
//String chinese = new String(output.getBytes("ISO8859-1"), "GBK");
System.out.println("number:"+s);
System.out.println("chinese:"+dx);
}
static String moneyD =new String();
static String moneyBefore=new String() ;
static String moneyAfter=new String();
static StringBuffer moneyA = new StringBuffer();
public static String getTurns(int i) {
switch (i) {
case 2 :
moneyD = "拾";
break;
case 3 :
moneyD = "佰";
break;
case 4 :
moneyD = "仟";
break;
case 5 :
moneyD = "万";
break;
case 6 :
moneyD = "拾";
break;
case 7 :
moneyD = "佰";
break;
case 8 :
moneyD = "仟";
break;
case 9 :
moneyD = "亿";
break;
case 10 :
moneyD = "拾";
break;
case 11 :
moneyD = "佰";
break;
case 12 :
moneyD = "仟";
break;
}
return moneyD.toString();
}
public static String getTurnMoneyWord(String s) {
switch (Integer.parseInt(s)) {
case 0 :
return "零";
case 1 :
return "壹";
case 2 :
return "贰";
case 3 :
return "叁";
case 4 :
return "肆";
case 5 :
return "伍";
case 6 :
return "陆";
case 7 :
return "柒";
case 8 :
return "捌"; }
return "玖";
} public static String getTurnMoneys(String money) {
try {
if (money.indexOf("-") != -1) {
moneyA.append("负");
money = money.substring(money.indexOf("-") + 1, money.length());
}
if (money.indexOf(".") != -1) {
moneyBefore= money.substring(0, money.indexOf("."));
moneyAfter = money.substring(money.indexOf(".") + 1, money.length());
} else {
moneyBefore = money;
moneyAfter = "none";
}
if (moneyBefore.length() == 1&& moneyBefore.charAt(0) == '0'&& moneyAfter == "none") {
moneyA.append("零");
moneyA.append("圆");
} else {
for (int i = 0; i < moneyBefore.length(); i++) {
if (moneyBefore.charAt(i) != '0') {
moneyA.append(getTurnMoneyWord(
String.valueOf(
String.valueOf(moneyBefore.charAt(i))).concat("")));
if (moneyBefore.length() != i + 1)
moneyA.append(getTurns(moneyBefore.length() - i));
continue;
}
if (moneyBefore.length() - i == 5&&( moneyBefore.length() > 5&& moneyBefore.length() <= 9))
moneyA.append("万");
if (moneyBefore.length() - i == 9&& moneyBefore.length() > 9)
moneyA.append("亿");
if (moneyBefore.length() != i + 1&& moneyBefore.charAt(i + 1) != '0')
moneyA.append("零");
}
if (moneyBefore.length() != 1 || moneyBefore.charAt(0) != '0') {
moneyA.append("圆");
}
}
if (!moneyAfter.equals("none")) {
for (int i = 0; i < moneyAfter.length(); i++) {
if (i == 0)
if (moneyAfter.charAt(i) != '0') {
moneyA.append(getTurnMoneyWord(String.valueOf( String.valueOf(
moneyAfter.charAt(i))).concat("")));
moneyA.append("角");
} else if (moneyBefore.charAt(0) != '0' && moneyAfter.length()>1 && (!moneyAfter.equals("00")))
moneyA.append("零");
if (i == 1 && moneyAfter.charAt(i) != '0') {
moneyA.append(getTurnMoneyWord(String.valueOf(
String.valueOf(moneyAfter.charAt(i))).concat(
"")));
moneyA.append("分");
}
} }
if (moneyAfter.equals("none") || moneyAfter.length() != 2 || moneyAfter.equals("00"))
moneyA.append("整");
} catch (Exception exception) {
}
return moneyA.toString();
}
public static void main(String str[]) throws IOException{
//double d=2302.6;
// String s= Double.toString(d);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String ss=getTurnMoneys(s);
System.out.println(ss);
}
}