發表文章

Merging a new object in java with an already existing one

圖片
up vote -2 down vote favorite I want to know how can i merge two objects in java. I've tried creating a 3rd class but to no avail. The first one being the this object and the next one is given through the method. Something like: import java.util.Arrays; public final class IntegerArray { private int a; public IntegerArray(int a) { this.a = a; } public int length() { return a.length; } public int getElementAt(int i) { return a[i]; } public int sum() { int sum = 0; for(int i: a) { sum += i; } return sum; } public double average() { int i, sum = 0, armean; for(i = 0; i < a.length; i++) { sum = sum + a[i]; } armean = sum / i; return armean...