In the previous section of "Running first JRuby program" example you must be aware with the way to run JRuby program. Now in this example you will know to "Calculate Factorial in JRuby".
In this example we have defined a function factorial( number) which takes the number as argument for which factorial is to be evaluated. Variable "n" will consists of the evaluated result finally and we can print the result by calling function factorial(). Here is the example code for calculating factorial in JRuby as follows:
# Define method factorial
if n = = 0
n * factorial(n-1)
# Printing factorial of 5
We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.
Posted on: September 29, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles