如何用java编一个程序将输入的阿拉伯数字转换成大写的汉字??
展开全部
import java.util.HashMap;
import java.util.Scanner;
public class Convert {
public static void main(String[] args) {
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(0, "零");
hashMap.put(1, "壹");
hashMap.put(2, "贰");
hashMap.put(3, "叁");
hashMap.put(4, "肆");
hashMap.put(5, "伍");
hashMap.put(6, "陆");
hashMap.put(7, "柒");
hashMap.put(8, "捌");
hashMap.put(9, "玖");
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
for (int i = 0; i < input.length(); i++) {
System.out.print(hashMap.get(input.charAt(i) - 48));
}
}
}
import java.util.Scanner;
public class Convert {
public static void main(String[] args) {
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
hashMap.put(0, "零");
hashMap.put(1, "壹");
hashMap.put(2, "贰");
hashMap.put(3, "叁");
hashMap.put(4, "肆");
hashMap.put(5, "伍");
hashMap.put(6, "陆");
hashMap.put(7, "柒");
hashMap.put(8, "捌");
hashMap.put(9, "玖");
Scanner scanner = new Scanner(System.in);
String input = scanner.next();
for (int i = 0; i < input.length(); i++) {
System.out.print(hashMap.get(input.charAt(i) - 48));
}
}
}
展开全部
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("");
}
}
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("");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用char强制转换就行,例如
public class test {
public static void main(String [] args){
char a=(char)19968;
char b='一';
System.out.println("a:"+a);
System.out.println("b:"+(b+1));
}
}
结果如下:
a: 一
b: 19969
ps:貌似理解错了,呵呵,看楼上的 switch吧
public class test {
public static void main(String [] args){
char a=(char)19968;
char b='一';
System.out.println("a:"+a);
System.out.println("b:"+(b+1));
}
}
结果如下:
a: 一
b: 19969
ps:貌似理解错了,呵呵,看楼上的 switch吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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();
}
}
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();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没看明白你的意思,一个阿拉伯数字对应一个汉字??用俩个数组,一个是数字,一个是汉字,然后去匹配
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询