public class DigitalConversion {
/**
* 100以内的数字转换为大写
* @param args
*/
public static void main(String[] args) {
int num = 24;
System.out.println(handleNum(num));
}
public static String handleNum(int num){
String[] numArray = {"","一","二","三","四","五","六","七","八","九","十"};
//存放大写数字
String numStr = "";
if (num > 0 && num <= 10){
numStr = numArray[num];
}else if (num > 10 && num < 100){
if (num % 10 == 0){
int n = num / 10 ;
numStr = numArray[n];
}else {
String nStr = String.valueOf(num);
//截取数字
String one = nStr.substring(0,1);
String two = nStr.substring(1,2);
if (num < 20){
numStr = "十" + numArray[Integer.parseInt(two)];
}else {
numStr = numArray[Integer.parseInt(one)] + "十" + numArray[Integer.parseInt(two)];
}
}
}else if (num == 100){
numStr = "一百";
}else {
numStr = String.valueOf(num);
}
return numStr;
}
}
java 将100以内的数字转大写
最新推荐文章于 2024-07-24 14:27:51 发布