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

Thread: How do you add a value to a 2-d array by row number and column number?

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

    Default How do you add a value to a 2-d array by row number and column number?

    Let's say I have a 2-d array of doubles of 3 rows and 5 columns named sales
    double [][] sales = new double [3][5];

    How do i add a value to a specific row and column, or cell? I am trying to write a program that asks user for the row number, the column number, the value to input and add that value to the cell/row and column?


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

    Default Re: How do you add a value to a 2-d array by row number and column number?

    You can change the contents of an array by assigning it a value using indexes:
    theArray{theRow][theCol] = theValue; //  assign value to slot

    Remember indexes start at 0 and go to the array length-1
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. sum of each row & column in 2-dimensional array.
    By muhammad waqar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 08:09 AM
  2. How do I return the current number of trades(number) from an array?
    By lovely92 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2012, 06:15 PM
  3. Replies: 3
    Last Post: October 26th, 2011, 03:37 PM
  4. Finding all Permutations that add up to a number.
    By godsfearme in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 28th, 2010, 03:54 PM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM

Tags for this Thread