Results 1 to 2 of 2
  1. #1
    Shaolin is offline Member
    Join Date
    Nov 2007
    Posts
    38
    Rep Power
    0

    Default Adding numbers in array

    Hi Guys,

    How can I workout the sum of money from an array:

    accs[0] = new Account( "Name here2", 121, 510 ) ;
    accs[1] = new Account( "Name here", 12, 50 ) ;

    I want to add the last 2 numbers for both items together to workout the total.

  2. #2
    ShoeNinja's Avatar
    ShoeNinja is offline Senior Member
    Join Date
    Oct 2007
    Posts
    124
    Rep Power
    0

    Default

    Since the array is made up of Account objects, you will need to access the data through methods in that class. Something like getBalance, getTotal..... After you have that method, it's pretty straightforward.

    Java Code:
    //assuming that the getBalance method returns an int
    int total = accs[0].getBalance() + accs[1].getBalance();

Similar Threads

  1. Prime numbers
    By gapper in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 10:09 AM
  2. Adding numbers in a 2 dimensional array
    By j0shizabeast in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 04:31 AM
  3. generating random numbers in a 5x5 array.
    By acidacid in forum New To Java
    Replies: 3
    Last Post: 08-14-2007, 03:44 AM
  4. how to swap 2 numbers
    By mary in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 05:32 PM
  5. Adding graphics to array
    By romina in forum Java 2D
    Replies: 1
    Last Post: 08-01-2007, 01:45 AM

Posting Permissions

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