使用 BigInteger 獲取錯(cuò)誤“變量 veryFar 可能尚未初始化”
我正在制作一個(gè)將數(shù)字轉(zhuǎn)換為文本的轉(zhuǎn)換器。我按照本網(wǎng)站中所說(shuō)的進(jìn)行了所有操作,并針對(duì)使用大整數(shù)進(jìn)行了編輯,但隨后顯示變量未初始化。我編輯了一些東西以使其與大整數(shù)兼容以獲得更大的數(shù)字,但它只是顯示變量 veryFar 可能未初始化。(我編輯了變量名來(lái)嘗試修復(fù)它?。?。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 條相同的錯(cuò)誤消息 - 錯(cuò)誤:變量 veryFar 可能尚未初始化 錯(cuò)誤:變量 veryFar 可能尚未初始化
查看完整描述