Question: I have my code which reads an array int list and outputs the digits and the sum and the copy , currently the output is

I have my code which reads an array int list and outputs the digits and the sum and the copy , currently the output is

intList[4]: 10 intList[3]: 8 intList[2]: 33 intList[1]: 21 intList[0]: 6 Sum of intList = 78 Sum of copy = [I@6e2829c7

the sum of copy is supoosed to = 73 not all those random sybombols and digits, i cant seem to fix it the only changes i could make also made the copy = 78 which isnt correct, just need some help fixing the copy. thanks. code is in java using intellij

probably is a simple fix i just cant get it, thanks

here is the code

public class ArrayTask { public static void main(String[] args) { int[] intList = {5, 20, 32, 7, 9}; int sum = 0; for (int i = 0; i < intList.length; i++) { //for loop to increase each element by 1 intList[i]++; } for (int i = intList.length - 1; i >= 0; i--) { System.out.println("intList[" + i + "]: " + intList[i]); sum += intList[i]; } System.out.println("Sum of intList = " + sum); int[] copy = new int[intList.length]; //declare another array called copy with the same type as intList for (int i = 0; i < intList.length; i++) { //for loop to assign to each element of copy the respective element of intList copy[i] = intList[i]; } int copysum = 0; for (int i = 0; i < copy.length; i++) { copysum += copy[i]; } System.out.println("Sum of copy = " + copysum); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!