方法一:
public class test {
public static void main(String args[]) {
int ss = Integer.parseInt(args[0]);
if(ss==0)
System.out.println("零");
else if (ss==1)
System.out.println("壹");
else if (ss==2)
System.out.println("贰");
else if (ss==3)
System.out.println("叁");
else if (ss==4)
System.out.println("肆");
else if (ss==5)
System.out.println("伍");
else if (ss==6)
System.out.println("陆");
else if (ss==7)
System.out.println("柒");
else if (ss==8)
System.out.println("捌");
else if (ss==9)
System.out.println("玖");
else
System.out.println("");
}
}
方法二:
import java.io.*;
public class Test1 {
public static void main(String[] args) {
//数据字典!
char
c[]={'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};
//等待输入!
System.out.print("请输入一个阿拉伯数字: ");
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
//得到输入!
try {
String
input=br.readLine();
for(int
count=0;count<input.length();count++){
//转成数字
char
temp=input.charAt(count);
switch
(temp){
case
'1':System.out.print(c[1]);break;case
'2':System.out.print(c[2]);break;
case
'3':System.out.print(c[3]);break;case
'4':System.out.print(c[4]);break;
case
'5':System.out.print(c[5]);break;case
'6':System.out.print(c[6]);break;
case
'9':System.out.print(c[9]);break;case
'8':System.out.print(c[8]);break;
case
'0':System.out.print(c[0]);break;default:break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
方法三:
class Test {
private
static HashMap map;
static
{
map = new HashMap();
map.put(new Character('0'), "零");
map.put(new Character('1'), "壹");
map.put(new Character('2'), "贰");
map.put(new Character('3'), "叁");
map.put(new Character('4'), "肆");
map.put(new Character('5'), "伍");
map.put(new Character('6'), "陆");
map.put(new Character('7'), "柒");
map.put(new Character('8'), "捌");
map.put(new Character('9'), "玖");
}
public
static void main(String[] args) {
String str = "123456";
System.out.println(getNumberString(str));
str = "123423245566";
System.out.println(getNumberString(str));
}
public
static String getNumberString(String str) {
char ch[] = str.toCharArray();
StringBuffer buffer = new StringBuffer();
Character character;
for (int i = 0; i < ch.length; i++) {
character = new Character(ch[i]);
buffer.append(map.get(character));
}
return buffer.toString();
}
}
加载中,请稍候......