Overflow Error Trap Question?

Status
Not open for further replies.

Mutany

Ars Scholae Palatinae
1,119
something like this?

where 'n' is equal to the entered no. of terms by the user, this method is supposed to stop it from overflowing.

Code:
public void setNumberOfTerms(int n)

    {
        numberOfTerms =0;
        //will find the maximum acceptable no. of terms

        do 
        {
            if (factorial(numberOfTerms) <= (Double.POSITIVE_INFINITY/(numberOfTerms+1)))
                numberOfTerms++;
        } while (numberOfTerms <= n);
    }
 
Status
Not open for further replies.