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: multiplication table java 2D array

  1. #1
    Junior Member
    Join Date
    Dec 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default multiplication table java 2D array

    Hello fellow Java-Members!

    I am currently trying to solve the following problem, but I’ve been stuck in the last 2-3 days.

    Problem:

    Implement a method
     int[][] getMultiplicationTables(int from, int to)
    , which returns a 2D Array containing the results of the multiplicaton of all numbers for "int from - int to".

    Also, the values of the array should be displayed in columns in the console.


    What I’ve got so far is this:

    public class MultiplicationTables {
     
    	public void printTables(int from, int to) {
    		for(int i = from; i < to; i++) {
    			for(int j = from; j <= 10; j++) {
    				System.out.println(i * j);
    			}
    		}		
    	}
    }

    I just have no idea how to solve this with a 2D Array :/

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: multiplication table java 2D array

    how to solve this with a 2D Array
    First you need to solve the problem manually to get a design.
    Given two numbers, say 2 and 5 what should be the contents of the array?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Location
    Belgium
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: multiplication table java 2D array

    int from and int to are indexes? Where does your Array come from? Seems like your method shouldn't only take the indexes, but also the array.
    You could do something like:
    public class MultiplicationTables {
        public void printTables(int from, int to, int [][] yourArray) {
            for(int i = from; i < to; i++) {
    	    for(int j = from; j <= 10; j++) {
    	        System.out.println(yourArray[i][0] *yourArray[0][j]);
    	    }
                System.out.println();
            }		
        }
    }

Similar Threads

  1. Array table question
    By kingsta in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2013, 12:15 PM
  2. Java Multiplication Table
    By Thoros in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 18th, 2013, 01:57 PM
  3. 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
  4. Help on 2D Multi Table Array
    By clevel211 in forum Object Oriented Programming
    Replies: 1
    Last Post: February 1st, 2011, 04:28 AM
  5. HTML table to 2D array parser
    By Neruk in forum Algorithms & Recursion
    Replies: 2
    Last Post: January 28th, 2011, 07:16 AM

Tags for this Thread