R
R
Rishat Sultanov2016-09-15 19:43:49
Java
Rishat Sultanov, 2016-09-15 19:43:49

How to work with BigInteger correctly?

Good afternoon, ladies and gentlemen.
Tell me how to work with comparison operators in BigInteger?

import java.util.Scanner;
import java.math.*;

public class CalcBig
{

    public static void main(String[] args)
    {
        System.out.print("Введите любое целое число: ");
        Scanner scan = new Scanner(System.in);
        BigInteger number = scan.nextBigInteger();
        BigInteger factorial = CalcBig.fact(number);
        System.out.print(factorial);
    }
    private static BigInteger fact(BigInteger number)
    {
        if (number <= 0)
        {
            return BigInteger.valueOf(1);
        }
        else
        {
            return number * fact(number-1);
        }
    }
}

13850F56.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EmmGold, 2016-09-15
@EmmGold

Perhaps an explicit declaration of types is required. Java doesn't explicitly count everything as an integer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question