두 개의 간단한 java 파일에 몇 가지 BigInteger
오브젝트가 있습니다. 그러나, 그것들은 원시 타입이 아니기 때문에, 산술 연산자는 그것들에서 작동하지 않을 것입니다. 이 연산자를 사용 할 때마다 오류를 그래서 같은오브젝트에 대한 산술 연산 방법
: 여기
.\_Mathematics\Formulas\Factorial.java:10: error: bad operand types for binary o
perator '*'
result *= i;
^
first type: BigInteger
second type: int
그들은 다음과 같습니다
package _Mathematics.Formulas;
import java.math.*;
public class Factorial<T extends Number> {
public T o;
public BigInteger r;
public Factorial(int num) {
BigInteger result = new BigInteger("1");
for(int i = num; i > 0; i--)
result *= i;
this.o = num;
this.r = result;
}
}
및
package _Mathematics.Formulas;
import java.math.*;
public class Power<T extends Number> {
public T o;
public BigInteger r;
public Power(T num, int pow) {
BigInteger result = new BigInteger(1);
for(int i = 0; i < pow; i++) {
result *= num;
}
this.o = num;
this.r = result;
}
}
내가 잠시 동안 주위를 둘러 보았다 이 문제를 해결하는 방법에 대해서는 답변을 찾을 수 없습니다.
누군가가이 문제를 해결할 수 있습니까?
감사합니다.
BigInteger javadoc을 보셨습니까? – sanbhat