Exercise #2 Implement an instance method belonging to the IntArrayBag class that takes two input parameters, oldVal and newVal. The method replaces each oldVal element in the array with newVal. Make sure to include the method header.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 2CP
icon
Related questions
Question

Exercise #2

Implement an instance method belonging to the IntArrayBag class that takes two input parameters, oldVal and newVal. The method replaces each oldVal element in the array with newVal. Make sure to include the method header.

Expert Solution
Step 1

Logic:- 

Define array elements . 

Read oldVal and newVal

pass arrayName,oldVal and newVal to method instance. 

In method definition, iterate from i=0 to i<arrayName.length

   Check if arrayName[i]==oldVal

         ArrayName[i]=newVal

   End loop

In main display newArray elements. 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT