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.

 채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 27일

1 개 추천

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)
ans = 12345678934 ans = 24691357868 ans = 123456789340

댓글 수: 2

Walter Roberson
Walter Roberson 2022년 2월 27일
If i can reach more than 2^53 then you would need a slightly different approach.
Ammy
Ammy 2022년 2월 27일
Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2022년 2월 27일

댓글:

2022년 2월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by