我试图在将BigInteger变量除以整数变量时打印商的值,但编译器显示“线程中的异常”主“java.lang.RuntimeException:无法编译的源代码 - 二元运算符的错误操作数类型” /'first type:java.math.BigInteger第二种类型:int“
public static void main(String[] args) {
String s;
BigInteger n, repeat, remainder;
Scanner in=new Scanner(System.in);
s=in.nextLine();
n=in.nextBigInteger();
repeat=n/s.length();
System.out.println(repeat);
}
答案 0 :(得分:1)
使用BigInteger.divide方法执行操作。 (/ operand仅适用于基本类型。)
import java.math.BigInteger;
import java.util.Scanner;
public class ModuloTest {
public static void main(String[] args) {
String s;
BigInteger n, repeat, remainder;
Scanner in = new Scanner(System.in);
s = in.nextLine();
n = in.nextBigInteger();
BigInteger length = BigInteger.valueOf(s.length());
repeat = n.divide(length);
System.out.println(repeat);
}
}