# 数字自然读法

package test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;

/**
*
*/
public class NianShuZi {

/**
* 本程序可读x为整数且-10^12 gt x lt 10^12
*/
private static final String[] cnnumber = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
private static final String[] cnsep = {"万", "亿"};
private static final String[] limits = {"十", "百", "千"};

public static void main(String[] args) {

String number = "100000101";

boolean negflag = false;

if (number.contains("-")) {
number = number.substring(1);
negflag = true;
}
if (number.length() == 1 && Integer.parseInt(number) == 0) {
System.out.println(cnnumber[0]);
return;
}
if (result.startsWith("一十")) {
result = result.replaceFirst("一十", "十");
}
result=result.replaceAll("零+", "零");
if (negflag) {
result = "负" + result;
}
System.out.println(result);
}

//读lt4
private static String read4Digits(String[] numbers) {
boolean zeroFlag = true;
for (int i = 0; i < numbers.length; i++) {
if (i == 0) {
if (!numbers[i].equals("0")) {
} else {
zeroFlag = false;
}
} else {
if (numbers[i].equals("0")) {
if (zeroFlag == true) {
zeroFlag = false;
}
} else {
zeroFlag = true;
}
}
}
}

//读lt12
private static String read12Digits(String number) {
String[] numbersAll = number.split("(?<=.)(?=.)");
Collections.reverse(Arrays.asList(numbersAll));
boolean partzeroflag = true;
for (int i = 0; i < (numbersAll.length - 1) / 4 + 1; i++) {
String[] numbers = Arrays.copyOfRange(numbersAll, i * 4, (i + 1) * 4 > numbersAll.length ? numbersAll.length : (i + 1) * 4);
int total = 0;

for (String j : numbers) {
total += Integer.parseInt(j);
}
if (i == 0) {
if (total != 0) {
} else {
partzeroflag = false;
}
} else {
if (total == 0) {
if (partzeroflag == true) {
partzeroflag = false;
}
} else {
partzeroflag= true;
}
}

}
String result = sb.toString().replaceAll("\\p{ASCII}", "");
return result;
}
}

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 0
评论
04-11 1690
05-16 4943
08-19 74
10-20 1736
07-31 1093
06-10
10-14
05-16
11-15
05-19
05-19

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。