This looks very trivial and is not a home work question.
public void sum(int[] arr){
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
System.out.println(arr[i]+"+"+arr[j]+"+"+"="+(arr[i]+arr[j]));
}
}//end of sum function
This prints all the sum of each elements. This is O(n^2).
I want to know if this could be solved more efficiently.
Since A + B is equal to B + A, you could just check the elements after the initial element in index
i:It’s still O(n^2)/2, so the complexity is still basically quadratic.