Problem with ArrayList Append example


#1
public int[] append(int[] list1, int[] list2) {
    int[] a = new int[list1.length + list2.length];
    int i = 0;
    
    for(int j = 0; j < list1.length; j++) {
        a[i] = list1[j];
        i++;
    }
    
    for(int j = 0; j < list2.length; j++) {
        a[i] = list2[j];
        i++;
    }
    
    return a;
    }
public static void main(String[]args){
    Append a = new Append();
    int[]num={1,2,3};
    int[]num2={3,5,6};
    a.append(num2, num);
    System.out.println(a);
}
}

Everytime I run the app it returns just fine but I see no array of integers. I just get something like this:
Application2Append@15db9742


#2

If anybody can tell me why this isn’t working that would be the best.


#3

what is your class? I am unsure, can you use repl.it to duplicate the problem? I attempted it here:

https://repl.it/@stetim94/OpenOvercookedAsiantrumpetfish

but am unsure what classes you are using, and they are not in the code you included


#4

its the same name as the method. And I figured out what it was. I had to instantiate another array for the actual append method and set it equal to the method at hand. Then print out the array. Thanks for the reply though! :slight_smile:
I’m doing arrays for the next week though. If you guys are wondering.

int[] append=append(num2, num);

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.