永发信息网

求java程序 输入数字,输出相应汉字

答案:2  悬赏:80  手机版
解决时间 2021-03-27 14:24
  • 提问者网友:献世佛
  • 2021-03-27 06:12
求java程序 输入数字,输出相应汉字
最佳答案
  • 五星知识达人网友:你可爱的野爹
  • 2021-03-27 07:18
public class Test{
public String transfer(long num){
String s = num + "";
s = s.replace("0", "零");
s = s.replace("1", "壹");
s = s.replace("2", "贰");
s = s.replace("3", "叁");
s = s.replace("4", "肆");
s = s.replace("5", "伍");
s = s.replace("6", "陆");
s = s.replace("7", "柒");
s = s.replace("8", "捌");
s = s.replace("9", "玖");
return s;
}
}
全部回答
  • 1楼网友:怙棘
  • 2021-03-27 08:56
import java.util.*;
public class test{
public static void main(String []args){
long l=}
public String transfer(long l){
String[] unit1={"零","一","二","三","四","五","六","七","八","九"};
String[] unit2={"","十","百","千"};
String[] unit3={"","万","亿","万亿"};
String result="";
//先将该数每四位分割成一快,如123456789:分为1,2345,,6789;放在list中;
List list=new LinkedList();
while(l!=0){
list.add(l%10000);
l=l/10000;
}
for(int i=0;i String s="";
long temp=list.get(i);
for(int j=0;j<4;j++,temp=temp/10){
if(temp%10!=0){
System.out.println(temp%10);
s=unit1[(int)(temp%10)]+unit2[j]+s;
}
}
s=s+unit3[i];
result=s+result;
System.out.println(result);
}
return result;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯