[java]代码库
import java.util.Scanner;
public class Zhuanhuan {
static String wei []={"分","角","元","拾","佰","千","万"};
static String han []={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
static String output="";
public static void main(String[] args){
String c="";
System.out.println("输入一个数"); //输入一个String类型的数字
Scanner sc=new Scanner(System.in);
c=sc.nextLine();
sc.close();
zhuanhuan(c);
}
public static void zhuanhuan(String a)
{
char b[];
String t="";
b=a.toCharArray(); //将输入的数转化为char类型的数组
int c=a.indexOf('.'); //定位小数点的位置
for(int i=0;i<c;i++) //将小数点前后的数字分别进行转化
{
int k=b[i]-48;
t+=han[k]+wei[c+1-i];
}
for(int i=c+1;i<a.length();i++)
{
int k=b[i]-48;
t+=han[k]+wei[a.length() - i - 1];
}
System.out.println(t);
}
}
[代码运行效果截图]
by: 发表于:2017-08-04 14:56:58 顶(1) | 踩(2) 回复
??
回复评论