Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2013
    Posts
    29
    Rep Power
    0

    Default 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

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default 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!

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

    Default Re: Multiplication table

    The first step i think i do know:
    Java Code:
    ArrayList<Integer> mt = new ArrayList<Integer>();
    however the second step im having trouble on please help:)

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default 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.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Please help with multiplication table.
    By psx2514 in forum New To Java
    Replies: 4
    Last Post: 04-04-2013, 04:59 AM
  2. Multiplication Table
    By BillyB in forum New To Java
    Replies: 17
    Last Post: 12-24-2010, 07:58 AM
  3. Multiplication Table
    By SwEeTAcTioN in forum New To Java
    Replies: 4
    Last Post: 02-24-2010, 05:11 AM
  4. Multiplication table
    By rjones215 in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 05:34 PM
  5. Help with multiplication table
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 05:44 PM

Posting Permissions

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