1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Serhud [2]
3 years ago
14

Write a public member function which replace that replaces one occurrence of a given item in the ArrayBag with another passed as

an argument. The method should return a boolean to indicate whether the replacement was successful.
Computers and Technology
1 answer:
ira [324]3 years ago
5 0

Answer:

The method is written in Java

public static boolean abc(int [] ArrayBag,int num, int replace){

    Boolean done = false;

    for(int i =0; i<ArrayBag.length;i++){

        if(ArrayBag[i] == num){

            ArrayBag[i] = replace;

            done = true;

        }

    }

    for(int i = 0;i<ArrayBag.length;i++){

        System.out.println(ArrayBag[i]+" ");

    }

    return done;

}

Explanation:

The method is written in java

The arguments of the method are:

<em>1. ArrayBag -> The array declares as integer</em>

<em>2. num -> The array element to check the presence</em>

<em>3. replace - > The replacement variable</em>

This line defines the method as boolean.

public static boolean abc(int [] ArrayBag,int num, int replace){

This line declares a boolean variable as false

    Boolean done = false;

The following iterates through the elements of the array

    for(int i =0; i<ArrayBag.length;i++){

This checks if the array element exist

        if(ArrayBag[i] == num){

If yes, the array element is replaced

            ArrayBag[i] = replace;

The boolean variable is updated from false to true

            done = true;

        }

    }

The following iteration prints the elements of the array

<em>     for(int i = 0;i<ArrayBag.length;i++){</em>

<em>         System.out.println(ArrayBag[i]+" ");</em>

<em>     }</em>

This prints returns the boolean thats indicates if replacement was done or not.

    return done;

}

<em>Attached to this solution is the program source file that includes the main method of the program</em>

Download txt
You might be interested in
Anyone else having problems with edg?
Kamila [148]
No what’s your problem on edge
4 0
2 years ago
Can someone help me asap​
vichka [17]

Sorry but Your screwed

4 0
3 years ago
Which type of shape allows you to add text that can be moved around.
Kipish [7]

Answer:

Move a text box, WordArt, or shape forward or backward in a stack. Click the WordArt, shape, or text box that you want to move up or down in the stack. On the Drawing Tools Format tab, click either Bring Forward or Send Backward.

3 0
2 years ago
There's an App for That!
AleksandrR [38]

Answer:

Im confused man

Explanation:

6 0
3 years ago
A body performing Shm has a velacity of 12m/s when the displacement is 100mm the displacement
Assoli18 [71]

Answer:

vjcyfuy

Explanation:

yjvjy

4 0
3 years ago
Other questions:
  • The programming interface between an application program and the dbms is usually provided by the
    13·1 answer
  • On a spreadsheet, this is the term for a grouping of cells that touch each other and form a rectangle. An example of it would be
    13·1 answer
  • im in honors comupter science and one of my questions is evaluate 18% 7 does anyone know how to answer that
    6·1 answer
  • Analytical CRM systems are the input for operational CRM systems.<br><br> True<br><br> False
    11·1 answer
  • What computer is designed to meet the computing needs of several people simultaneously in a small to medium-size business enviro
    5·1 answer
  • What is meant by the phrase "backing up your data"?
    15·1 answer
  • A model is replica that?
    11·2 answers
  • Compound conditions require a computer to sense whether multiple conditions are true or false.
    9·1 answer
  • 1. Write an if statement that assigns 20 to the variable y, and assigns 40 to the variable z
    10·1 answer
  • The purpose of __________________ is to isolate the behavior of a given component of software. It is an excellent tool for softw
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!