第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

確定數(shù)字中數(shù)字的基本程序不適用于更高的數(shù)字?

確定數(shù)字中數(shù)字的基本程序不適用于更高的數(shù)字?

浮云間 2022-08-17 12:22:15
我制作了一個(gè)小代碼塊,其目標(biāo)是嘗試將數(shù)字的所有數(shù)字存儲(chǔ)到數(shù)組中。例如,數(shù)字“123”將存儲(chǔ)為 {1,2,3}。一切似乎都運(yùn)行良好,除非數(shù)字的長(zhǎng)度大于10。是我的方法有問(wèn)題嗎?確切的錯(cuò)誤消息是線程“main” java.lang.NumberFormatException 中的異常:對(duì)于輸入字符串:“1202020202020202020” at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Integer.parseInt(Integer.java:652) at java.base/java.lang.Integer.parseInt(Integer.java:770) at test.main(test.java:8)public class test {public static void main(String[] args){    //This block of code parses the zipcode and stores each number it has into an array. It also fetches the length, which is used later.    String input = args[0];           int length = input.length();    int zipcode = Integer.parseInt(args[0]);    int[] digits = new int[length];             for(int i = 0; i < length ; i++){         digits[i] = zipcode % 10;         zipcode = zipcode /10;    }}}
查看完整描述

1 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

您的代碼將處理的最大數(shù)字是 Integer.MAX_VALUE,這是2147483647。除此之外,您正在嘗試解析一個(gè)不適合整數(shù)的數(shù)字。使用Long會(huì)給你更多的空間。

剛剛看到@user207421的評(píng)論,他/她是對(duì)的...你真的不需要把你的字符串存儲(chǔ)為一個(gè)數(shù)值。如果您必須這樣做,并且想要處理非常大的數(shù)字,則可以使用BigDecimal。

另外,根據(jù)你說(shuō)你想要的,我認(rèn)為你的最終數(shù)組將按照你想要的順序相反。


查看完整回答
反對(duì) 回復(fù) 2022-08-17
  • 1 回答
  • 0 關(guān)注
  • 131 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)