1 public static void main(String[] args) { 2 // TODO Auto-generated method stub 3 Scanner scanner=new Scanner(System.in); 4 System.out.print("请输入小写数字:"); 5 int number=scanner.nextInt(); 6 String res=""; 7 res=change(number); 8 System.out.println("转换为大写数字:"+res); 9 10 } 11 public static String change(int number){ 12 String[] bigwrite={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"}; 13 char[] str = String.valueOf(number).toCharArray(); 14 //将整型转化为字符型,通过调用toCharArray方法接收字符串 15 String rstr = "";//用来接收字符的数组 16 for (int i = 0; i <str.length; i++) { 17 rstr = rstr + bigwrite[Integer.parseInt(str[i] + "")]; 18 } 19 /* 20 * Integer.parseInt(str[i] + "")字符串下标为i的字符转换成整型 21 */ 22 return rstr; 23 }
结果如下
请输入小写数字:0123456789
转换为大写数字:壹贰叁肆伍陆柒捌玖
String number=scanner.next();
改成字符串
明白了
对于整数来说 0123456789
会转成 123456789
换成字符串接收就可以了
谢谢啊
用字符串接收输入的小写数字,其他不用修改
具体实现:
public class Number {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("请输入小写数字:");
String number=sc.next();
String res="";
res=change(number);
System.out.println("装换为大写数字:"+res);
}
public static String change(String number){
String[] bigwrite={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char[] str=number.toCharArray();
//将整形转化为字符型,通过调用tocharArray方法接收字符串
String rstr="";//用来接收字符的数组
for(int i=0;i<str.length;i++){
rstr=rstr+bigwrite[Integer.parseInt(str[i]+"")];
System.out.println(rstr);
}
return rstr;
}
}
java相关问题可以在该网站查找:http://www.dashen100.com/question/985