Results 1 to 3 of 3

Thread: Adding Arrays

  1. #1
    oudaivd1 is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default Adding Arrays

    I am practicing on my arrays and im feeling pretty confident. But im struggling with this one error i keep getting. So if someone could tell me what im missing i would greatly appreciate it.

    package project12;

    /**
    *
    * @author David
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here
    //create a table 3x3

    double [][] firstTable = new double [3][3];
    double [][] secondTable = new double [3][3];
    double [][] sumTable;
    sumTable = addTables(firstTable, secondTable);


    double [][] sum = new double [firstTable.length][firstTable[0].length];

    }
    public static double addTables(double [][] firstTable,double [] [] secondTable, double [][] sumTable ){
    for (int r =0; r < firstTable.length; r++) {
    for (int c=0; c <firstTable[r].length; c++){
    sumTable [r] [c]= firstTable [r][c] + secondTable [r][c];
    }
    }
    return sumTable;

  2. #2
    Louis is offline Member
    Join Date
    Nov 2010
    Posts
    9
    Rep Power
    0

    Default

    addTables(firstTable, secondTable);
    here you pass 2 actual parameter(arguments) to addTable?

    public static double addTables(double [][] firstTable,double [] [] secondTable, double [][] sumTable ){
    Here you want 3 paramter in the paramter list.
    Is that error you want to find?

  3. #3
    m00nchile is offline Senior Member
    Join Date
    Feb 2010
    Location
    Ljubljana, Slovenia
    Posts
    470
    Rep Power
    10

    Default

    Also, you initialize your sumArray after the method call. Even if the addTables method worked (you're not calling it correctly btw), the results would be lost as you instantiate a new array.
    Ever seen a dog chase its tail? Now that's an infinite loop.

Similar Threads

  1. Adding letters to arrays??
    By mustachMan in forum New To Java
    Replies: 2
    Last Post: 07-19-2010, 01:37 AM
  2. Adding Arrays and Enhanced For Loop into program.
    By vinyacam in forum New To Java
    Replies: 1
    Last Post: 05-10-2010, 06:28 AM
  3. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 01:40 AM
  4. Adding two Arrays
    By Mayur in forum New To Java
    Replies: 1
    Last Post: 09-26-2009, 11:49 PM
  5. Adding Values of 2 Arrays
    By core2duo5252 in forum Java 2D
    Replies: 7
    Last Post: 09-05-2009, 03:50 AM

Tags for this Thread

Posting Permissions

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