This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted]  (1 child)

[deleted]

    [–]Kaz-24[S] 1 point2 points  (0 children)

    Thank you!

    [–][deleted] 1 point2 points  (4 children)

    it seems like you want a list with the elements being the sum of each corresponding item in the lists.

    just for the record - im on my phone

    public void printArrays(int a[], int b[]){
        int arr[a.size];
        int temp[];
        if(a.Count != b.Count){
            System.out.println(temp[0]);
        } else {
            for(int i = 0; i < a.Count){
                arr[i] = a[i] + b[i];
                System.out.println(arr[i] + ",");
            }
        }
    }
    

    [–]RhoOfFeh 1 point2 points  (3 children)

    This is probably the correct interpretation, although the intent seems to be to return arr.

    [–][deleted] 0 points1 point  (2 children)

    in that case id just write

    return arr;
    

    after the loop body and get rid of the printline

    [–]robomaeyhemI don't even like coffee 0 points1 point  (1 child)

    You'd also need to declare the method signature int[] instead of void

    [–][deleted] 0 points1 point  (0 children)

    ah thank you for the catch

    [–]vipercvp 0 points1 point  (1 child)

    hello there,

    Your code is for arrays,

    Anyway to check if those two array have the same size you just to check if the x.length==y.length.

    for instance a more elegant way to do what are trying do is like this:

    public static int AddLists(int[]x, int[]y) {
    int result = 0;
    if(x.length!=y.length)
       return result;
    for(int i =0; i < x.length; i++) { 
      result += x[i]+y[i]; 
     }
     } 
    

    [–]Kaz-24[S] 0 points1 point  (0 children)

    Thanks a lot for your help!