Sign in to follow this  
rodrickbrown

Multiplication Grid Help!

Recommended Posts

I have an assignment to create a class that does the following.
MultiTable table = new MultiTable(3,3); 
should output the following 

 *    0    1    2
--------------------
 0   |0    0    0
 1   |0    1    2
 0   |0    2    4
I have most of it work but I'm not sure how to get the horizontal bar, I'm not even sure if my approach is even correct any feedback appreciated thanks.
--- MultiTable.java ---
public class MultiTable {
    private int[][] multiTable;

    MultiTable(int row, int col)
    {
        multiTable = new int[row][col];
        for(int r = 0; r < row ; r++)
        {
            for(int c = 0; c < col; c++)
            {
                multiTable[r][c] = r*c;
            }
        }
    }

    public void displayTable()
    {
        System.out.print(" \t*");
        for(int r = 0; r < multiTable.length; r++)
        {
            for(int c = 0; c < multiTable[r].length; c++)
            {
                if(c == 0)
                {
                    System.out.print("\t " +  r + "\t");                    
                }
            }
        }
        System.out.println();


        for(int r = 0; r < multiTable.length; r++)
        {
            System.out.print("\t" + r + "\t|");
            for(int c = 0; c < multiTable[r].length; c++)
            {
                System.out.print(multiTable[r][c] + "\t\t");
            }
            System.out.println();
        }
    }
}

--- Main.java --- 
public class Main {
    public static void main(String[] args)
    {
        MultiTable table = new MultiTable(3,3);

        table.displayTable();
    }
}

My code output :(
* 0 1 2 0 |0 0 0 1 |0 1 2 2 |0 2 4 [code]

Share this post


Link to post
Share on other sites
From the forum FAQ:

9. Do not ask homework related questions. The Gamedev.net members are not here to answer your homework questions, its against the forum rules and few people take kindly to it. Besides, we shouldn't need to tell you that figuring it out for yourself will be way more beneficial to you in the long run.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBolton
From the forum FAQ:

9. Do not ask homework related questions. The Gamedev.net members are not here to answer your homework questions, its against the forum rules and few people take kindly to it. Besides, we shouldn't need to tell you that figuring it out for yourself will be way more beneficial to you in the long run.


I wasnt looking for a handout as I've dont 95% of the work on my own.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this