Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java Multiplication Table

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Multiplication Table

    Hello, I'm new to java and am completely lost in this program I am supposed to create.

    This program should have six methods:

    intro ()
    This method will output a welcome message to the user.
    getRows()
    This method will ask the user for the number of rows they would like in their multiplication table. It will set the row array to the size the user requests.
    getCols()
    This method will ask the user for the number of columns they would like in their multiplication table. It will set the column array to the size the user requests.
    fillRows()
    This method will fill the row array with the numbers to be used to multiply against the column array to get the multiplication table.
    fillCols()
    This method will fill the column array with the numbers to be used to multiply against the row array to get the multiplication table.
    printTable()
    This method will print the size of the table, the headers for the columns and rows, as well use for loops to print the multiplication table

    the output should be like

    Welcome to the Multiplication Table Program!
    Enter number of rows:6
    Enter number of columns:4


    Here is your 6 x 4 multiplication table:


    1 2 3 4
    ---------------------------
    1| 1 2 3 4
    2| 2 4 6 8
    3| 3 6 9 12
    4| 4 8 12 16
    5| 5 10 15 20
    6| 6 12 18 24

    Here's what I've got so far:

    import java.util.Scanner;
     
    public class MultTable
    {
    	public static void main ( String args[] )
    	{
    	int[] rows;
    	int[] cols;
    	}
     
    	public void intro();
    	{
    		System.out.println("Welcome to the Multiplication Table program!");
    	}
     
    	public int getRows(int[] rows)
    	{	
    		int numr;
    		Scanner input = new Scanner(System.in);
    		System.out.print("Enter number of rows: ");
    		numr = input.nextInt();
    	}
     
    	public int getCols(int[] cols)
    	{	
    		int numc;
    		Scanner input = new Scanner(System.in);
    		System.out.print("Enter number of columns: ");
    		numc = input.nextInt();
    	}
     
    	public int fillRows(int[] rows);
    	{
     
    	}
     
    	public int fillCols(int[] cols);
    	{
     
    	}
     
    	public int printTable(int[] cols, int[] rows);
    	{
    		for(int i = 1; i < rows.length; i++)
    			{
    				rows[i] = i;
    			}
     
     
    		for(int j = 1; j < cols.length; j++)
    			{
    				cols[j] = j;
    			}
     
    	}
     
    }

    I am unsure of how I should tackle the fillRows() and fillCools() methods. I have a relative idea of what the printTable() should be like, but other than that, I am lost.

    I would be grateful to anyone who can help through this.


  2. #2
    Junior Member
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java Multiplication Table

    I actually did this type of problem recently. Check out this

    Code removed
    Last edited by jps; April 18th, 2013 at 01:42 PM. Reason: Removed spoonfed code

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Java Multiplication Table

    Quote Originally Posted by Thoros View Post
    I am unsure of how I should tackle the fillRows() and fillCools() methods.
    Both of these methods should fill an array counting up to the number given by the user, respectively.
    The forum cuts out leading white spaces, but be sure your table output is evenly aligned, unlike in the post.
    Last edited by jps; April 18th, 2013 at 01:59 PM. Reason: alignment

Similar Threads

  1. need help java multiplication table
    By darking123 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 2nd, 2012, 08:49 AM
  2. simple multiplication exercise.
    By saintnicks in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 22nd, 2012, 08:36 PM
  3. Multiplication program
    By PhilThomspon in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 6th, 2012, 01:54 PM
  4. Having problem in matrix multiplication....
    By sidhant in forum Java Theory & Questions
    Replies: 5
    Last Post: March 17th, 2011, 01:41 PM
  5. Multiplication code
    By bomboy in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 5th, 2011, 02:25 AM

Tags for this Thread