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
How would I copy this image?
Dahasolnce [82]

Question: <em>How would I copy this image?</em>

Answer: Either screenshot it, or CTRL C ± CTRL V it. To screenshot something, open 'snipping tool' and pull up the PDF, then box in whatever you are trying to copy. You can also reverse image search it to find it somewhere on the web.

Uplifting Note: To you, smiling at someone may mean nothing, but to them, it might be their whole world.

3 0
3 years ago
50 points, and brainliest if u get it right!
marshall27 [118]

Answer:

they are games in which payoffs are initially negative for both players and progress

6 0
3 years ago
You are running Windows 8 on your laptop. You install a 64-bit application on it. Where will this application reside on your com
melamori03 [73]
In the Program Files folder.
6 0
3 years ago
Read 2 more answers
The memory management layer is the part of the kernel that serves out all memory allocation requests.
svetlana [45]
Most likely it’s False . But look it up just in case
4 0
3 years ago
How can your web page design communicate your personal style
Levart [38]

Answer:

Web design is very unique, you can express your feelings through creating a page.

7 0
3 years ago
Other questions:
  • Digital manipulation is commonly referred to as _______. Kodaking photo-oping Photoshopping photofixing
    6·2 answers
  • To connect multiple usb devices to a single usb port, a ____ can be used.
    12·1 answer
  • Many of the special staff teams require leadership training, which is offered to staff with more than 1 year of service at Camp
    15·1 answer
  • How do you take a picture on this app
    10·1 answer
  • Which of the following are types of home internet service? Check all that apply
    7·1 answer
  • ICMP
    12·1 answer
  • Explain the difference between invention and innovation?
    13·1 answer
  • Use Python.
    7·1 answer
  • What is combo chart ? how will you created a combo chart​
    11·2 answers
  • Please answer questions in complete sentences!
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!