The Artima Developer Community
Sponsored Link

Java Answers Forum
adding elements od an array

4 replies on 1 page. Most recent reply: Mar 16, 2004 4:33 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Nancy

Posts: 11
Nickname: ac121107
Registered: Feb, 2004

adding elements od an array Posted: Mar 15, 2004 8:19 PM
Reply to this message Reply
Advertisement
How can I add the elements of an array?
Thank you
Nancy


Coolest Head

Posts: 5
Nickname: stkovrflow
Registered: Mar, 2004

Re: adding elements od an array Posted: Mar 15, 2004 8:53 PM
Reply to this message Reply
Are u asking how to increase the size of an array or how to add a simple element to the array.

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: adding elements od an array Posted: Mar 15, 2004 11:10 PM
Reply to this message Reply
String [] stringArr = new String[10];
stringArr[0] = "Java";
stringArr[1] = "Aminur";
//Keep on adding

Nancy

Posts: 11
Nickname: ac121107
Registered: Feb, 2004

Re: adding elements of an array Posted: Mar 16, 2004 4:03 AM
Reply to this message Reply
I would like to know how to add the existing elements of the array.
For example if I have
int array[]{1,2,3}
How can I get the program to add 1+2+3
Thank you
Nancy

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: adding elements of an array Posted: Mar 16, 2004 4:33 AM
Reply to this message Reply
int sum=0;
for(int i=0;i<array.length;i++)
{
     sum = sum+array[i];
}
 

Flat View: This topic has 4 replies on 1 page
Topic: Compilation Error Previous Topic   Next Topic Topic: still having Problems

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use