DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: For Loops

  1. #1
    Join Date
    Dec 2004
    Posts
    12

    For Loops

    Hi,

    Using a for loop, I have wrote a program that displays a “6 times table” multiplication table:

    public class TimesTable3_4a
    {
    public static void main(String[] args)
    {
    int table = 6;

    for ( int row=1; row<=12; row++ )
    {
    System.out.println( row + " * " + table + " = " +
    ( table * row ) );
    }
    }
    }


    How could I adapt the above program so that instead of a “6 times” table, the user chooses which table is displayed?

    Thanks in advance.

  2. #2
    Join Date
    Oct 2004
    Posts
    311
    the user can gice the program info in the following way:

    java TimesTable3_4a 6

    This would give a 6 to the application.
    Parameters passed to applications in such a way end up in the String[] args variable.
    (order in wich they appear is the same as wich they were entered on command line.

    This should send you in the right way...

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links