подсчитав нули в факториальном числе, пожалуйста, проверьте ошибку - PullRequest
0 голосов
/ 27 июня 2018

Ошибки компиляции

Main.java:18: error: method mod in class BigInteger cannot be applied to given types;
r = factorialans.mod(10);
                        ^
required: BigInteger
found: int
reason: actual argument int cannot be converted to BigInteger by method invocation conversion
Main.java:22: error: method divide in class BigInteger cannot be applied to given types;
            factorialans = factorialans.divide(10);
                                       ^
  required: BigInteger
  found: int
  reason: actual argument int cannot be converted to BigInteger by method invocation conversion
2 errors

import java.util.Scanner;
import java.math.BigInteger;

class Main  {
    public static void main(String args[]) {
        BigInteger r;
        BigInteger factorialans=new BigInteger("1");

        int n,i,count=0;
        Scanner sc=new Scanner(System.in);
        n = sc.nextInt();
      //factorial...
        for (i = n; i > 0; i--){
            factorialans = factorialans.multiply(BigInteger.valueOf(i));
        }

            System.out.print(factorialans);

        while(!factorialans.equals(0)){
          r = factorialans.mod(10);
            if (r.equals(0)){
                count++;
            }
            factorialans = factorialans.divide(10);
        }
        System.out.print(count);
    }
}

1 Ответ

0 голосов
/ 27 июня 2018

См. документ , его следует использовать следующим образом:

public BigInteger mod(BigInteger m)

public BigInteger divide(BigInteger val)

Вы можете изменить это на:

factorialans.mod(BigInteger.valueOf(10)) 

и

factorialans.divide(BigInteger.TEN)
...