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
Blizzard [7]
3 years ago
7

Given the following function definition, what modifications need to be made to the search function so that it finds all occurren

ces of target in the array?int search(const int array[], int target, int numElements){int index=0;bool found=false;while((!found) && (index < numElements)){if(array[index] == target)found=true;elseindex++;}if(found==true)return index;elsereturn -1;}a. Add another parameter to indicate where to stop searchingb. Add another parameter to indicate where to start searchingc. This already can find all occurrences of a given targetd. Have the function return the whole array
Computers and Technology
1 answer:
svet-max [94.6K]3 years ago
8 0

Answer:

D. have function return the whole array

Explanation:

the given function only return first occurrence of target. In order to get all occurrences of target we have to change condition in while loop to check whole array even if first occurrence of target found and plus add another parameter of type array that will store different  indexes of occurrence of target and return that array

You might be interested in
12. ______ is considered to be the first video game mascot.
Tatiana [17]
D pac man im hope im right
7 0
3 years ago
The boolean expression:
Cerrena [4.2K]

Answer:

(A > B) || (C < D)

Explanation:

7 0
2 years ago
A simple algorithm for handling requests works like this:________ a) all requests users make are stored. b) The elevator priorit
bezimeni [28]

Answer:

b) The elevator prioritizes the requests that are on the way where it’s going, but also based on a first come first served principle.

Explanation:

Elevator routing often looks complex, as the elevator has to decide whether to go to the person who has waited the longest or the one who is closest? There are also issues of how long should the rider spend.

A simple algorithm can be designed where the elevator prioritizes the requests that are on the way where it’s going, but also based on a first come first served principle. Once it exhausts the request in its current direction, it then switches directions if there are requests in that direction. This way the elevator is able to tackle the complex issue based on the simple algorithm.

8 0
3 years ago
Read 2 more answers
In this exercise you will debug the code which has been provided in the starter file. The code is intended to take two strings,
vampirchik [111]

Answer:

Here is the corrected program:

import java.util.Scanner; //to accept input from user

public class 02_14_Activity_one { //class name

    public static void main(String[] args) { //start of main method

    Scanner scan = new Scanner(System.in); //creates Scanner class object

  System.out.println("Enter first string"); //prompts user to enter first string

          String s1 = scan.nextLine(); //reads input string from user

  System.out.println("Enter second string"); //prompts user to enter second string

          String s2 = scan.nextLine(); //reads second input string from user

    System.out.println("Enter number of letters from each word"); //enter n

          int n = scan.nextInt(); //reads value of integer n from user

          System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

         } } //uses substring method to print a string made up of the first n letters of s1 and the last n letters of s2.

Explanation:

The errors were:

1.

Scanner scan = Scanner(System.in);

Here new keyword is missing to create object scan of Scanner class.

Corrected statement:

 Scanner scan = new Scanner(System.in);

2.

String s1 = nextLine();  

Here object scan is missing to call nextLine() method of class Scanner

Corrected statement:

String s1 = scan.nextLine();

3.

String s2 = Scanner.nextLine();

Here class is used instead of its object scan to access the method nextLine

Corrected statement:

String s2 = scan.nextLine();

4.

String n = scan.nextLine();

Here n is of type String but n is a whole number so it should be of type int. Also the method nextInt will be used to scan and accept an integer value

Corrected statement:

int n = scan.nextInt();

5.

System.out.println(s1.substring(1,n-1) + s2.substring(s1.length()-n));

This statement is also not correct

Corrected statement:

System.out.println(s1.substring(0,n) + s2.substring(s2.length() - n ));

This works as follows:

s1.substring(0,n) uses substring method to return a new string that is a substring of this s1. The substring begins at the 0th index of s1 and extends to the character at index n.

s2.substring(s2.length() - n ) uses substring method to return a new string that is a substring of this s2. The substring then uses length() method to get the length of s2 and subtracts integer n from it and thus returns the last n characters of s2.

The screenshot of program along with its output is attached.

7 0
3 years ago
If $350 is the profit of an initial investment of $1000.00, what is the percentage profit?​
umka2103 [35]

Answer:

35%

Explanation:

1000x=350

x=350/1000

x=0.35

35%

6 0
3 years ago
Read 2 more answers
Other questions:
  • Janelle is organizing an outline for an investigative report about the benefits of taking a 30-minute walk each day. which of th
    11·2 answers
  • What dose a bios system do?
    5·2 answers
  • WILL UPVOTE &lt;3
    9·1 answer
  • 1.Terry turned on his computer one day to find that all of the storage on his computer was filled up. Furthermore, there were ma
    6·1 answer
  • Convert the following four unsigned binary numbers to decimal and show your work:
    14·1 answer
  • why is the disk method a special case of the general slicing​ method? choose the correct answer below. a. the cross sections of
    7·1 answer
  • Im bored anyone up for a convo? lets talk.. =D
    7·2 answers
  • Write a Python program that takes a file name as input and generates the following output: File size in bytes and KBs Time the f
    12·1 answer
  • In java I need help on this specific code for this lab.
    5·1 answer
  • The it components of an erp system architecture include the hardware, software and the ________
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!