Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

Explain the factors that determine the degree of decentralisation

Answered: 1 week ago

Question

What Is acidity?

Answered: 1 week ago

Question

Explain the principles of delegation

Answered: 1 week ago

Question

State the importance of motivation

Answered: 1 week ago

Question

Discuss the various steps involved in the process of planning

Answered: 1 week ago

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago