1. Member Join Date
Nov 2013
Posts
29
Rep Power
0

## Multiplication table

Steps are:

Create a new class, MultiplicationTable, that has a single field to store an integer multiplication table
Create a constructor that takes a parameter for the maximum number to be multiplied in the table. For example, MultiplicationTable(9) would have a maximum value of 81, where as MultiplicationTable(12) would have a maximum value of 144. Initialize the field in the constructor with the appropriate multiplication values.
Create a multiply method that takes two integers as parameters and returns their multiplication value by looking it up in the field. Make sure to test this method with values greater than the max the table should have stored. How can you handle these cases?
Create a main method that repeatedly tests multiply by printing out the entire multiplication table.

So far i got:

Java Code:
```package collectionsHw_netid;

class MultiplicationTable
{
// field
int mt;

MultiplicationTable(){
{
for (int i=0; i<=9; i++)

{
for (int j=0; j<=9; j++)
System.out.print(i+"*"+j+"="+(i*j)+"\t");
System.out.println();
}
}
}
public static void main(String args[])
{

}
}```
is my code right? also how do i print it out? the professor told us that everything should be outside of the main method... please help im still new  Reply With Quote

2. ## Re: Multiplication table

Back up. Items one and two on the assignment. One, how are you going to store a table in an int? Do you know about arrays? And two, do you know how to write a constructor that takes a parameter?  Reply With Quote

3. Member Join Date
Nov 2013
Posts
29
Rep Power
0

## Re: Multiplication table

The first step i think i do know:
Java Code:
`ArrayList<Integer> mt = new ArrayList<Integer>();`  Reply With Quote

4. ## Re: Multiplication table

Kudos for using a Collection instead of an array. But an ArrayList is analogous to a one-dimensional array, and a multiplication table is two-dimensional. You could make it work, but you'd have to simulate the second dimension. Here's a discussion about simulating 2D arrays in C. It's not a common technique in Java... though maybe it should be. Or you could use a list of lists, or a 2D array, which in Java is actually an array of arrays.  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•