Basic Java Question: Creating a two dimension array to output multiplication tables

Hello Everyone!

Now that I have some more free time, I am back to trying to understand JAVA. I have a basic script that needs a lot of work. I am trying to write an application using a two dimension array that will create a multiplication table. Below is an example of what I would like for it to ouput:

0     1     2     3     4     5     6
1     1     2     3     4     5     6
2     2     4     6     8     10     12
3     3     6     9     12     15     18
4     4     8     12     16     20     24
5     5     10     15     20     25     30
6     6     12     18     24     30     36

Basically, the results are obtained by multiplying the row and column values together. I have attached what I have so far but I do not really understand what I need to do to get the output above.

 * @(#)
 * test application
 * @author 
 * @version 1.00 2008/11/18
public class test {
    public static void main(String[] args) {
 long[][] table;           
  table = new long[x][y];
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      table[i][j] = i * j;

Open in new window

LVL 22
Joseph MoodyBlogger and wearer of all hats.Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Looks a bit like homework ...
Joseph MoodyBlogger and wearer of all hats.Author Commented:
More of a personal assignment.
How about something like this:
public class Dummy {
  public static void main(String[] args) {
    int x = 12;
    int y = 10;
    long[][] multi = new long[x][y];
    for( int i = 0;i < x;i++ )
      for( int j = 0;j < y;j++ )
        multi[i][j] = ( i + 1 ) * ( j + 1 );
    for( int i = 0;i < y;i++ ) {
      for( int j = 0;j < x;j++ ) {
        System.out.print(multi[j][i] + " ");

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Joseph MoodyBlogger and wearer of all hats.Author Commented:
Now that is pretty cool! There are some more things that I want to do with it but that now that I have a basic piece to build off of, I should be fine! Thanks!
Well - guess I was wrong and just getting the code was what was enough... which puts the question in the "do my homework category"... So friendly reminder for the experts - it is ok to help someone and to explain what they need to do - it's not so ok to write a full program and run away with no explanation :)


Good luck with Java - if the plan is to learn it.

By the way - you can change the first cycle a bit -- because the table is mirrored you can fill it with half the moved. So something like this wouold do (as your table is square. If it was not, you need to do some checks on the i,j before reverting
for( int i = 0;i < x;i++ )
      for( int j = i;j < y;j++ ){
        multi[i][j] = ( i + 1 ) * ( j + 1 );
        multi[j][i] = multi[i][j]

Open in new window

Joseph MoodyBlogger and wearer of all hats.Author Commented:
Thanks Venabili. I have actually spent the last hour disecting the code and I think it is making more sense to me. I do have one question that pertains to more of the array itself. What is the purpose of "long"?
long[][] multi = new long[x][y];

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.