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
What is an unique text-based internet address corresponding to a computer's unique numeric IP address called
FromTheMoon [43]

Answer:

This is called a domain name

Explanation:

A domain name is an address used by internet users to access a website.

6 0
3 years ago
Network address 192.10.10.0<br>​
Leona [35]

Answer:

That IP is near Cheney, Kansas

Explanation:

3 0
3 years ago
If you wanted to create a line of code that would add ten to the user’s current score, which code should you use?
Korvikt [17]

Answer:

choice c

Explanation:

score = score + 10

because the rest doesn't make since and score == score + 10 has an extra equal sign.

7 0
3 years ago
Read 2 more answers
Write a program that reads a list of integers into a list as long as the integers are greater than zero, then outputs the smalle
almond37 [142]

Answer:

Check the explanation

Explanation:

10

5

3

21

2

-6

the output will be somthing like this:

2 21

You can then suppose that the list of integers will contain at least 2 values.

4 0
3 years ago
What animal is perry the platypus ​
valkas [14]

Answer: Agent P or simply Perry

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Sahil is making a graphic novel in which the villain plans to reduce the rate at which energy is released from the Sun. The vill
    7·2 answers
  • Food is shipped thousands of miles throughout our country using various types of transportation such as trucks, planes, and boat
    10·1 answer
  • HELP AS SOON IS A UNIT TEST WILL GIVE BRAINLIEST
    9·2 answers
  • After saving her presentation initially, Leah realizes she needs to add another content slide. She adds the slide and is ready t
    7·1 answer
  • What is meant by backing up files through cloud computing?
    5·2 answers
  • An inventory clerk, using a computer terminal, views the following on screen: part number, part description, quantity on hand, q
    8·1 answer
  • Most operating systems today primarily use a ____.
    12·1 answer
  • The method needed to arrange for an object to be notified when a window's close-window button has been clicked is
    6·1 answer
  • Question 3
    13·1 answer
  • How many levels of heading tags are allowed in html?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!