Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Wayne Crawford   on Jul 03 In Java Category.

  
Question Answered By: Jamie Roberts   on Jul 03

I think this must solve your problem...

public class AddArray {
public static void main( String[] args ) {

int a[] = {2,3,5,6,7,8,9}; // Could be n size  going thru the list
int b[] = {5,7,2,9}; // also could be n size

if(a.length>b.length){
int temp=b.length;
for(int i=0;i<a.length;i++){
if(temp!=0){
System.out.println(a[i]+b[i]);
temp--;
}else{
System.out.println(a[i]);
}
}
}else{
int temp=a.length;
for(int i=0;i<b.length;i++){
if(temp!=0){
System.out.println(a[i]+b[i]);
temp--;
}else{
System.out.println(b[i]);
}
}
}


}
}

Share: 

 
 
Didn't find what you were looking for? Find more on ADD Array Problem Or get search suggestion and latest updates.


Tagged: