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 5 of 5

Thread: How can I add two data arrays ?

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I add two data arrays ?

    public static int[] arrayAdd(int[] p, int[] q) {

    for (int i = 0; i < p.length; i++) {
    for (int j = 0; j < q.length; j++) {
    int add [] = p[i] + q[j];

    }

    }
    return add;
    }

    Hi, i dont know, how to add two simple data array....can you help mi please ?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    19,996
    Thanks
    47
    Thanked 2,138 Times in 2,111 Posts

    Default Re: How can I add two data arrays ?

    What does the posted code do that is wrong?
    Can you explain what your problem is? Do you get errors?
    Please post the full text of the error messages.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I add two data arrays ?

    My problem is, that it doesnt work...i just want add two arrays and save it to the new array. And i dont know how i can use this function with the specific numbers ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    19,996
    Thanks
    47
    Thanked 2,138 Times in 2,111 Posts

    Default Re: How can I add two data arrays ?

    it doesnt work.
    What does the code do when you execute it?

    Have you tried writing down on a piece of paper what you want to happen for each element in the three arrays to see how to use the for loop and its index?
    Write one expression on each line showing the array references and the values of the array indexes.
    Last edited by Norm; November 6th, 2011 at 03:00 PM.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,465
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: How can I add two data arrays ?

    int add [] = p[i] + q[j];

    What does that line do? Think about it carefully and be very exact.
    Improving the world one idiot at a time!

Similar Threads

  1. Data is covered by latter data
    By ljz1031 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 15th, 2011, 08:04 PM
  2. Replies: 2
    Last Post: June 15th, 2011, 03:49 PM
  3. Replies: 1
    Last Post: June 11th, 2011, 05:39 AM
  4. error related arrays outputting wront data...
    By semicolon in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 1st, 2011, 09:34 AM
  5. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM