[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
Lame addition/sum problem  XML
Forum Index » Java Programming
Author Message
leapfrog7

Newbie

Joined: 02/11/2010 23:30:17
Messages: 13
Offline

Okay, so I am working on this program, and have been for a while now. I have the line of code:



This code works and does what it is intended to. However, I added a button to add more elements to the array, but I still need this total.

My question is how do I total elements in an array without knowing how many elements I will have? I ask this because the button allows the user to add 0 - ? additional elements. So it will be "unknown".

Can anybody help?
stdunbar

Newbie
[Avatar]

Joined: 06/22/2005 14:51:37
Messages: 849
Location: Superior, CO, USA
Offline

The number of elements in an array can always be accessed with the length member variable



Thanks for using the forums at hotjoe.com
[WWW] [Yahoo!] [ICQ]
leapfrog7

Newbie

Joined: 02/11/2010 23:30:17
Messages: 13
Offline

Thank you so much, that helped a lot. All I came up with on my own was



Which worked for the elements that were already written in the code, but when I added new elements it would not re-total the elements, but your example worked perfectly. Thank you again!
 
Forum Index » Java Programming
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle