• Advertisement
Sign in to follow this  

Multiplication Grid Help!

This topic is 4003 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites
Advertisement
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
Sign in to follow this  

  • Advertisement