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
A hot spot is the __________. A. Point that collides with other objects B. Point an object spins around when it rotates C. First
Ber [7]
I would think it's A
5 0
4 years ago
A _____, or spider, is a search engine program that automatically searches the web to find new websites and update information a
Len [333]

Answer: B) Web robot

Explanation:

Web robot or spider is the search engine program which automatically visit the new web site and update the information. Basically, it is the internet bot that helps in store the information from the search engine to the index.

Spider searches the web site and read the information in their given page for creating the entries from search engine.

Web robot is also known as web crawler, this type of programs are use by different search engine that automatically download and update the web content on web sites.  

3 0
4 years ago
Write a program to help a travelling sales person keep up with their daily mileage driven for business. In your main method, the
Lelu [443]

Answer:

The programming language is not stated;

<em>The program written in C++ is as follows (See Explanation Section for detailed explanation);</em>

#include<iostream>

using namespace std;

int main()

{

 int numdays;

 cout<<"Number of days of mileage: ";

 cin>>numdays;

 int miles[numdays];

for(int i=0;i<numdays;i++)

{

 cout<<"Miles traveled on day "<<i+1<<": ";

 cin>>miles[i];

}

 int total = 0;

 for(int i=0;i<numdays;i++)

{

 total+=miles[i];

}

cout<<"Total mileage traveled: "<<total;

 return 0;

}

Explanation:

This line declares the number of days of mileage

 int numdays;

This line prompts user for days of mileage

 cout<<"Number of days of mileage: ";

This line accepts input from the traveler for days of mileage

 cin>>numdays;

This line creates an array

 int miles[numdays];

The italicized is an iteration that collects the user input for each day

<em> for(int i=0;i<numdays;i++)</em>

<em> {</em>

<em>  cout<<"Miles traveled on day "<<i+1<<": ";</em>

<em>  cin>>miles[i];</em>

<em> }</em>

This line initializes variable to 0

 int total = 0;

The italicized is an iteration that adds up the mileage traveled by the traveler each day  

<em>  for(int i=0;i<numdays;i++)</em>

<em> {</em>

<em>  total+=miles[i];</em>

<em> }</em>

This line prints the total miles traveled

cout<<"Total mileage traveled: "<<total;

5 0
4 years ago
In _________, the process requests permission to access and modify variables shared with others. A) entry section B) critical se
AleksAgata [21]

In entry section, the process requests permission to access and modify variables shared with others.

<h3>What is Entry section?</h3>

Entry Section is known to be an aspect of any given process that tells the entry of a specific process.

Note that it often allows one process to enter and alter the shared variable and as such, In entry section, the process requests permission to access and modify variables shared with others.

Learn more about entry section from

brainly.com/question/1637572

#SPJ1

3 0
2 years ago
Ask the user to input a number less than 100. Print all the numbers from that number to 100.
Ber [7]

Answer:

The second one:

num = int (input("Enter a number between 1 and 100: "))

c = num

while (c <= 100):

print (c)

c = c + 1

Explanation:

First of all, you don't know Python... (LEARN IT)

Second of all, The first loop doesn't make sense? num 100

And the second one works, you can try compiling it (lazy to explain...).

8 0
3 years ago
Read 2 more answers
Other questions:
  • A rich text format (RTF) provides an electronic image of a document and can be viewed, printed, and electronically transmitted.
    7·1 answer
  • which option will joan use to get a glimpse of how her presentation will look like when she presents it to her audience
    11·2 answers
  • A virus is a name given to a small text file that's placed on your computer by the designers of the website when you visit that
    6·1 answer
  • How can I lag my computer as if it had bad internet?
    15·1 answer
  • Long-tail keywords are:
    9·1 answer
  • Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the
    14·1 answer
  • 25 points!!!!!!!!!!!!!!!!!!!!!
    9·2 answers
  • What is the meaning of compiler​
    14·1 answer
  • NAT addresses concerns over the dwindling IPv4 address space by ___________________. 1 point allowing networks to use fewer IP a
    15·1 answer
  • What refers to a set of instructions executed in order?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!