Multiplication table using 2 for loops in Java
I saw this search term coming up over and over again in my wp-stats, I would guess that this is a school assignment–for those beginning to get into grips with Java language, this is how to generate the Multiplication table using 2 for loops; you could use another kind of loop, but using ‘for’ is by far the simplest that I can think of.
The size of the multiplication table is determined by the values of rows and columns integer variables, just replace the values according to your need.
"\t" is an escape code for tabs, we'd like each vaulue in our table to have a somewhat uniform spacing, and for this reason too, the System.out.print was used--we don't want to have a new line everytime we print a value, we only want the new line after one complete row (the maximum value of the rows variable, which is the outer for loop) -- which is why the System.out.print("\n") is positioned in the outer for loop.
compile and run using
$ javac MultiplicationTable.java
$ java MultiplicationTable
{1 Comment below .. you can add one }
8.2.2010at 00:53
thnx! this is something similar to what i wanted.