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
If you want to access your home network from your distant garage, a ________ might help boost the signal.
Kryger [21]
Wireless range extender.
6 0
2 years ago
Name two purposes of creating a microsoft account for use in visual studio 2015
Kazeer [188]
Creating a Microsoft account for use in Visual Studio 2015 means that you will get a better and optimized user experience, with several benefits.
Some of the purposes why you should create an account are:
1. free software, training and support from Visual Studio and broad range of benefits
2. synchronized Visual Studio Settings, which means that you will have for example the same layout, window and color theme, or whatever you select in the settings, every time you log in with your account


4 0
3 years ago
Thanks for help evreybody
ladessa [460]

Answer:

np

Explanation:

7 0
3 years ago
Read 2 more answers
Anyone help me please​
MissTica

Answer:

1. True

2. False

3. True

4. False

5. True

6. True

7. False

4 0
3 years ago
Read 2 more answers
Alexander studies sitting on the edge of his bed with his laptop on his lap. he complains of a sore neck. how can he best improv
kumpel [21]

The way in which Alexander can best improve his study area is that: D. he can put his computer on a desk and sit in a comfortable chair.

<h3>What is a laptop?</h3>

A laptop can be defined as a small, portable type of computer that is designed and developed by embedding both a mousepad and keyboard on it.

Also, it is usually light enough to be placed on an end user's lap while he or she is working.

In this scenario, the way in which Alexander can best improve his study area is that he can put his computer on a desk and sit in a comfortable chair.

Read more on a laptop here: brainly.com/question/26021194

#SPJ4

7 0
1 year ago
Other questions:
  • Where can you access email accounts on your windows 7 computer in order to modify current accounts or create new ones?
    5·1 answer
  • I wonder how world is created
    12·2 answers
  • Which cost of purchasing a franchise would you still have if you start your own business​
    12·1 answer
  • A law office has been leasing dark fiber from a local telecommunications company to connect a remote office to company headquart
    14·1 answer
  • When discussing the data-modeling building blocks, anything (a person, a place, a thing, or an event) about which data are to be
    15·1 answer
  • The image below shows a weather service map
    13·1 answer
  • Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you
    10·1 answer
  • An online supermarket wants to update its item rates during the sales season. They want to show the earlier rates too but with a
    6·2 answers
  • Differenciate between foreign key and primary key in database.
    8·1 answer
  • Have the javascript function CountingMinutes(str) take the str parameter being passed which will be two times (each properly for
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!