More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Calculating factorial in JRuby 
 

In the previous section of "Running first JRuby program" example you must be aware with the way to run JRuby program.

 

Calculating factorial in JRuby

                         

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:

 

 

 


JRubyFactorail.rb

require "java"
# Define method factorial 
     def factorial(n)
        if n = = 0
           1
       else
          n * factorial(n-1)
       end
    end
# Printing factorial of 5 
puts factorial(5).to_i


 Output:

C:\JRuby>jruby JRubyFactorial.rb
120


Download Code

                         

» View all related tutorials
Related Tags: c ruby ide class ant variables scope classes variable sed const constants jruby name using instance ria this id tar

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.