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

Printing Table in JRuby

In the previous sections of JRuby tutorials you have studied how to run program in JRuby and to calculate factorial in JRuby.

Printing Table in JRuby

                         

In the previous sections of JRuby tutorials you have studied how to run program in JRuby and to calculate factorial in JRuby. Now in this part of JRuby tutorial we will tell you how to take input in  JRuby from the console and print output table on the console output.

This example to print table will take input from the console and this is being done with the "gets" method. To print table we have used loop control 
"upto...do...end". Here is the example code for generating table in JRuby as follows:

 

 

 

 

JRubyTable.java

# Printing Table in JRuby

print " Enter number to print table := "
n= gets 
1.upto(10) do |i|
puts "#{n} * #{i} = #{n.to_i * i.to_i}"
end

To execute this program execute this JRubyTable.rb with jruby command. This will ask for a value to calculate factorial and generate result according to given value.

Output:

C:\JRuby>jruby JRubyTable.rb
Enter number to print table := 6
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60

Download Source Code

                         

» View all related tutorials
Related Tags: c ruby oop io for-loop loop jruby vi this oo show for ie example to exam sh e il section

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 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
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

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

Copyright © 2008. All rights reserved.