我正在制作一个将数字转换为文本的转换器。我按照本网站中所说的进行了所有操作,并针对使用大整数进行了编辑,但随后显示变量未初始化。
我编辑了一些东西以使其与大整数兼容以获得更大的数字,但它只是显示变量 veryFar 可能未初始化。(我编辑了变量名来尝试修复它!)。
package com.example.convertnumbertotext;
import java.math.BigInteger;
import java.text.DecimalFormat;
public class EnglishNumberToWords {
private static BigInteger bi = new BigInteger("100");
private static BigInteger bi2 = new BigInteger("20");
private static BigInteger bi3 = new BigInteger("10");
private static final String[] tensNames = { "", " ten", " twenty", " thirty", " forty",
" fifty", " sixty", " seventy", " eighty", " ninety" };
private static final String[] numNames = { "", " one", " two", " three", " four", " five",
" six", " seven", " eight", " nine", " ten", " eleven", " twelve", " thirteen",
" fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen" };
private static String convertLessThanOneThousand(BigInteger number) {
String veryFar;
BigInteger[] bii = number.divideAndRemainder(bi);
BigInteger[] bii2 = number.divideAndRemainder(bi3);
int resut = bii[1].compareTo(bi2);
if (resut == -1) {
veryFar = numNames[bii[1].intValue()];
number = number.divide(bi);
} else if (resut == 1 || resut == 0) {
veryFar = numNames[bii2[1].intValue()];
number = number.divide(bi3);
veryFar = tensNames[bii2[1].intValue()] + veryFar;
number = number.divide(bi3);
}
if (number.compareTo(BigInteger.valueOf(0)) == 0)
return veryFar;
return numNames[number.intValue()] + " hundred" + veryFar;
}
}
它显示 2 条相同的错误消息 - 错误:变量 veryFar 可能尚未初始化 错误:变量 veryFar 可能尚未初始化
慕哥9229398
桃花长相依
相关分类