我想總結一個非常大的數字。我得到的數字長度爲
l = answer.bitLength()
但我無法弄清楚如何使用For循環增加每個數字。有任何想法嗎?我正在使用java.math.biginteger
。如何在VB.Net中使用與biginteger相當的indexof()?
Visual Studio 2005的2.0版
我還要補充一點,我似乎無法使用<>或任何與我使用的BigInteger的簡單的數學選項。如果有人能告訴我如何使用不同的大整數,我會更願意交換。
Dim answer As java.math.BigInteger
Dim sum As Integer = 0
Dim x As Integer
Dim i As Integer
'Sets value of answer equal to 1
answer = java.math.BigInteger.valueOf(1)
'gets 100!
For i = 1 To 100
answer = answer.multiply(java.math.BigInteger.valueOf(i))
Next
'gets length of answer
Dim l As Integer
l = answer.bitLength()
'Sums up digits in 100!
For x = 0 To l - 1
'Need to pull each character here to add them all up
Next
總結數字的最終解決方案。感謝togoghe。
Dim r As Integer
Dim s As Integer
s = 0
While (answer.compareTo(java.math.BigInteger.valueOf(0)) > 0)
r = answer.mod(java.math.BigInteger.valueOf(10)).ToString()
s = s + r
answer = answer.divide(java.math.BigInteger.valueOf(10))
End While
你試過了什麼?你能發表你想要做什麼的僞代碼嗎? – Oded 2011-01-25 20:56:21
沒有`System.Numerics.BigInteger`的`bitLength`(甚至是`BitLength`)成員。你確定你沒有考慮Java嗎? – LukeH 2011-01-25 21:01:52