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
Consider what fact-finding techniques you would use to identify the important facts needed to develop a database system. Please
8090 [49]

Answer:

Examples of Fact-finding techniques includes:

  1. Prototyping
  2. Questionnaires
  3. Research and sites visit
  4. Interviews

Explanation:

It is important to note that a database system is a tool that allows users to define, create, maintain, and control access to a collection of logically related data and description of these data, designed to meet the information needs of an organization.

<u>Prototyping </u>

<em>Advantage:</em>  enables testing and understanding of the system in advance before final implementation of solution, while requiring less time for research.

<em>Disadvantage:</em> Training and Development cost consumes resources.

<u>Research and site visit </u>

<em>Advantage :</em> better time management if the problem has been researched upon before.

<em>Disadvantage:</em> appropriate permission is often needed before using research materials.

<u> Questionnaires </u>

<em>Advantage: </em>This technique is not expensive, and responses can be calculated and analysed quickly.

<em>Disadvantage:</em> There may be Incomplete answers received from users and body language of user cannot be observed.

<u>Interviews</u>

<em>Advantage:</em> The body language of interviewees is been perceived.

<em> Disadvantage: </em>Interviewing is time consuming and costly.

3 0
3 years ago
Assume the following instruction mix for some program:______.
m_a_m_a [10]

Answer:

the answer is fart

Explanation:

5 0
3 years ago
How many possible keys does the playfair cipher have? an approximate power of 2
Lorico [155]
I don't know but I am guessing 666 or 777 or 888.
7 0
3 years ago
4.8% complete this is a single choice question; skip ahead to question content a b c d confirm difficulty level: moderate an int
PilotLPTM [1.2K]

Answer:

A replay attack

4 0
2 years ago
F he continues to make monthly payments of $100, and makes no new purchases, how many more payments will he have to make before
castortr0y [4]

What is the interest rate?

Divide the total amount due by 100.

8 0
3 years ago
Other questions:
  • What languages do most of the students at Miami High School speak?
    6·2 answers
  • Sam has installed a new CPU in a client’s computer, but nothing happens when he pushes the power button on the case. The LED on
    14·1 answer
  • Markup is best defined as
    11·1 answer
  • Casey, a woodworker, is developing his own website. He plans to use the site as a means of selling his handmade furniture. While
    10·1 answer
  • A program uses two classes: dog and poodle. which class is the base class and which is the derived class?
    7·2 answers
  • Which of the following is NOT part of the URL for an Internet web site?
    13·1 answer
  • Write a nested loop to set values as follows: [0] [1] [2] [3] [4] [0] 1 2 3 4 5 [1] 1 2 3 4 5 [2] 1 2 3 4 5 [3] 1 2 3 4 5
    12·1 answer
  • Working with do-while loop
    9·1 answer
  • What is the classification of the Gartner company?
    9·1 answer
  • The residual volume can be measured directly with: Select an answer and submit. For keyboard navigation, use the up/down arrow k
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!