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
Each JavaScript command line ends with a(n) ____ to separate it from the next command line in the program.
kykrilka [37]
The answer is :
semicolon (;)
8 0
2 years ago
Which one of the following items is an example of software?
Harlamova29_29 [7]
Word processing program is an example of a software. All the others, such as Printer, Keyboard and Mouse are examples of Computer peripheral devices or in short hardware devices. Generally these listed hardware devices come under input or output computer device category. Also, by classic meaning in layman terms these hardware components can be touched or felt. In contrast, a word processing program is a part of a computer system that consists of data or computing instructions and provides the mechanism to computer to perform a certain task utilizing it's hardware resources. Such components of computer system which are written using one of the computer languages are called computer software or software programs or simply software.
4 0
3 years ago
Which numbering system is used for some network addresses, to describe colors
FromTheMoon [43]
Hexadecimal it describes locations in memory
5 0
3 years ago
A bulb has a resistance of 15Ω and is rated at 3A. What is the maximum voltage that can be applied across the bulb?
Anastasy [175]

Answer:Wheres the option choice??????????????????????

Explanation:

7 0
2 years ago
Which of the following statements is CORRECT? a. Multiple IRRs can occur only if the signs of the cash flows change more than on
BigorU [14]

Answer: i think the answer is

a. Multiple IRRs can occur only if the signs of the cash flows change more than once.

Explanation:

3 0
2 years ago
Other questions:
  • Your company is developing a new marketing campaign and wants to know which customers have never placed an order. You will need
    10·1 answer
  • Your new home has a vacuum system. what kind of computer is controlling it?
    5·1 answer
  • Java provides a(n) ____ class, which contains many useful methods for manipulating arrays.
    5·1 answer
  • When you set the position property for a block element to fixed, the element
    5·1 answer
  • The loss of privacy data has implications:
    5·1 answer
  • In your opinion is it more beneficial to have many folders or is it better to nest subfolders
    12·1 answer
  • Please help me. Adnan also wants to add a photograph of a bridge. It is on another PowerPoint presentation that is open in a dif
    11·1 answer
  • 2.13 LAB: Branches: Leap Year
    11·1 answer
  • How does abstraction help us write programs
    11·1 answer
  • Que es tarjeta madre resumen porfa
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!