Results 1 to 4 of 4
Thread: Multiplication table
 02262014, 09:42 PM #1Member
 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[]) { } }
 02262014, 11:36 PM #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?
Get in the habit of using standard Java naming conventions!
 02272014, 01:56 AM #3Member
 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>();
 02272014, 02:26 AM #4
Re: Multiplication table
Kudos for using a Collection instead of an array. But an ArrayList is analogous to a onedimensional array, and a multiplication table is twodimensional. 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.
Get in the habit of using standard Java naming conventions!
Similar Threads

Please help with multiplication table.
By psx2514 in forum New To JavaReplies: 4Last Post: 04042013, 03:59 AM 
Multiplication Table
By BillyB in forum New To JavaReplies: 17Last Post: 12242010, 06:58 AM 
Multiplication Table
By SwEeTAcTioN in forum New To JavaReplies: 4Last Post: 02242010, 04:11 AM 
Multiplication table
By rjones215 in forum New To JavaReplies: 3Last Post: 10192009, 04:34 PM 
Help with multiplication table
By Albert in forum New To JavaReplies: 1Last Post: 07102007, 04:44 PM
Bookmarks