How to resolve the problem in for loop?
1 次查看(过去 30 天)
显示 更早的评论
import java.math.*;
A = BigInteger('12345678934');
B = BigInteger('10');
for i =1:double(10)
i = BigInteger('i');
X(i) = i.multiply(A);
end
I'm facing the following error
Java exception occurred:
java.lang.NumberFormatException: For input string: "i"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.math.BigInteger.<init>(BigInteger.java:470)
at java.math.BigInteger.<init>(BigInteger.java:606)
How to resolve this issue?
Thanking in anticipation.
0 个评论
采纳的回答
Walter Roberson
2022-2-27
import java.math.*;
A = BigInteger('12345678934');
B = BigInteger('10');
for i =1:double(10)
iB = BigInteger(i);
X(i) = iB.multiply(A);
end
X(1), X(2), X(end)
2 个评论
Walter Roberson
2022-2-27
If i can reach more than 2^53 then you would need a slightly different approach.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!