帮你做了下~~
import java.io.*;
public class MoneyTest {
private String money=null;
private String strmoney="";
public MoneyTest(String money){
this.money=money;
}
public String getTheRMB()
{
int moneylength=money.length();
int intmoney=0;
try{
intmoney=Integer.parseInt(money);
}catch(Exception e)
{
e.printStackTrace();
}
int lengthtemp=moneylength;
int intmoneytemp=intmoney;
String danwei=null;
String num=null;
if(check(moneylength, intmoney)){
while(lengthtemp>0)
{
int x=1;
for(int i=0;i<lengthtemp-1;i++)
{
x=x*10;
}
int h=intmoneytemp/x;
intmoneytemp=intmoneytemp%x;
switch(h)
{
case 1:num="一";break;
case 2:num="二";break;
case 3:num="三";break;
case 4:num="四";break;
case 5:num="五";break;
case 6:num="六";break;
case 7:num="七";break;
case 8:num="八";break;
case 9:num="九";break;
case 0:num="";break;
default :System.out.println("数字有问题!等等!");
}
switch(lengthtemp)
{
case 5 :danwei="万";break;
case 4 :danwei="千";break;
case 3 :danwei="百";break;
case 2 :danwei="十";break;
case 1 :danwei="元";break;
default:System.out.println("单位有问题!等等!");
}
strmoney=strmoney+num+danwei;
lengthtemp--;
}
return strmoney;
}
return null;
}
private boolean check(int moneylength, int intmoney) {
if(moneylength==0)
{
System.out.println("请输入金额!");
return false;
}else if(intmoney>65536)
{
System.out.println("您输入的金额太大,请输入正确的金额!");
return false;
}
return true;
}
/**
* @param args
*/
public static void main(String[] args) {
try{
System.out.print("请输入金额:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String money1=br.readLine();
MoneyTest mt=new MoneyTest(money1);
String RMB=mt.getTheRMB();
System.out.println("您输入的金额是“"+RMB+"”");
}catch(Exception e){
e.printStackTrace();
}
}
}