Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Craig Daniels   on Jun 04 In Java Category.

  
Question Answered By: Dang Tran   on Jun 04

heres the code which does exactly what u want. u may modify it so that
it looks better eg aray sizes should be hardcoded etc

the code is displays the output  on the standard outout which is the
console.

public class AddArray
{
public static void main(String[] args)
{
int a[]= {1,2,3,4,5};
int b[]= {9,2,4,7,1};

/* I want to add  this whole array  to my final  output will be

10, 4, 7, 11, 6
*/

int c[] = new int[5];
for (int i = 0; i < 5; i++)
{
c[i] = a[i] + b[i];

}

for (int i = 0; i < 5; i++) System.out.println(c[i]);

}
}

Share: 

 
 
Didn't find what you were looking for? Find more on How to Add two Array Or get search suggestion and latest updates.


Tagged: