把金额转化为大写方式,实在想不错来怎么回事,程序还没有写完,
但是编译有6个错误,刚开始学JAVA,忘大家见谅,谢谢啦!
//Program ChangeMoney.java
//Change the number to the capitalization
//Date 6th-Mar-2007
public class ChangeMoney
{
private String Replace(char pos)
{
switch ( pos )
{
case 0:
return "零";
break;
case 1:
return "壹";
break;
case 2:
return "贰";
break;
case 3:
return "叁";
break;
case 4:
return "肆";
break;
case 5:
return "伍";
break;
case 6:
return "陆";
break;
case 7:
return "戚";
break;
case 8:
return "捌";
break;
case 9:
return "玖";
break;
default:
//throw a error;
}
}
private String Change(String money)
{
String resultStr = new String("");
int len = money.length() ;
if ( len-3 == money.indexOf('.') )
{
resultStr = Replace(money.charAt[len-2]) + "角" +
Replace(money.charAt[len-1]) + "分" + resultStr;
}
if ( len-2 == money.indexOf('.') )
{
resultStr = Replace(money.charAt[len-2]) + "角" + resultStr;
}
if ( -1 == money.indexOf('.') || len-1 == money.indexOf('.') )
{
resultStr = "元整" + resultStr;
}
return resultStr;
}
public static void main(String [] args)
{
ChangeMoney ch = new ChangeMoney();
System.out.println(args[0]+"表示为: "+ch.Change(args[0]));
}
}
[此贴子已经被作者于2007-3-6 16:38:08编辑过]