For Loops


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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...

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center