Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Problem 1854. Factorial: Unlimited Size : java.math

Created by Richard Zapor

This challenge is an application of java.math that allows unlimited precision calculations. The primary reference sites are Java Math, Java BigDecimal, and Java BigInteger.

The usage of BigDecimal function multiply will be essential.

Java Math tutorial: (Simplified summary that is believed correct)

vd-decimal value, vstr-string, vi-integer value 
xBD=java.math.BigDecimal(vd);  % valid vd,vstr,vi creates xBD a BigDecimal variable
import java.math.*;  % simplifies statements
xmultiplyzBD=xBD.multiply(BigDecimal(z));  % multiply input requires BD type
To convert java to string of unlimited length can be achieved via java toString or Matlab char
xstr=toString(xBD)  or xstr=char(xBD) 

Input: N [1< N < 1000]

Output: Y (char variable of Y=N! or a BigDecimal variable)

Factorial Calculator

Related Challenges:

1. Usage of java math

2. nchoosek_large (full precision)
2. Next Prime
3. factor_large
4. Factorial


Problem Group

Solution Statistics

23 correct solutions 3 incorrect solutions
Last solution submitted on Feb 09, 2016

Solution Comments