answer.
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
charle [14.2K]
1 year ago
12

A function defined beginning with void SetNegativesToZeros(int userValues[], ... should modify userValues such that any negative

integers are replaced by zeros. The function _____.
Computers and Technology
1 answer:
Stels [109]1 year ago
3 0

Answer:

   public static void setNegativesToZero(int userValues[]){

       System.out.println("Array before setting negatives to zero "+Arrays.toString(userValues));

       for(int i=0; i<userValues.length; i++){

           if(userValues[i]< 1){

               userValues[i] = 0;

           }

       }

       System.out.println();

       System.out.println("Array After setting negatives to zero "+Arrays.toString(userValues));

   }

Explanation:

Using Java programming Language, the method is created to receive an array of ints as parameter (as specified in the question)

Using a for loop, we iterate over the entire array checking for values that are negative (<0) and setting them to zero.

See a complete program below

import java.util.Arrays;

import java.util.Scanner;

public class num1 {

   public static void main(String[] args) {

   // Create an array and assign values

       int [] arr = {1,2,3,-1,1,2,-4};

   //Calling the method setNegativesToZero

   setNegativesToZero(arr);

   }

//Creating the Method

   public static void setNegativesToZero(int userValues[]){

       System.out.println("Array before setting negatives to zero "+Arrays.toString(userValues));

       for(int i=0; i<userValues.length; i++){

           if(userValues[i]< 1){

               userValues[i] = 0;

           }

       }

       System.out.println();

       System.out.println("Array After setting negatives to zero "+Arrays.toString(userValues));

   }

}

You might be interested in
Peter took a selfie in his room. He was a wearing a light blue shirt. But he failed to realize that that shirt would clash in co
Leto [7]

Answer:

A wand tool is to do that in an editing software.

7 0
1 year ago
Read 2 more answers
Write a program that defines a type for a structure that stores information on a student in ENG EK 125. Declare two variables to
Mashcka [7]

Answer:

Following are the program in the C Programming Language.

#include<stdio.h> //header file

#include<string.h> //header file

struct student//creating structure

{

 //set integer variables

int marks;

int roll;

};

//define function

void initial(struct student *stu)

{

 //set integer type variables

int marks=420;

int roll_no=45,i;

stu->marks=marks;//assigning the values

stu->roll=roll_no;//assigning the values

}

//define main method to call the function

int main()

{

struct student stu;

initial(&stu);//calling the function

printf("Total marks : %d\n",stu.marks); //print output

printf("Roll No. : %d\n",stu.roll); //print output

return 0;

}

<u>Output:</u>

Total marks : 420

Roll No. : 45

Explanation:

Here, we define the structure "student" with a struct keyword for creating a structure.

  • inside the structure, we set two integer type variable "marks", "roll".

Then, we define a function "initial()" and pass an argument in the parameter of the function.

  • inside the function, we set two integer type variable "marks", "roll_no" and assign the value in the variable "marks" to 420 and variable "roll_no" to 45.
  • Assign the value in the structure's integer variables from the function's variable.

Finally, we set the main method inside it we call the function "initial()" and pass the value and then, we print the output with message.

8 0
2 years ago
You are consulting for a trucking company that does a large amount ofbusiness shipping packages between New York and Boston. The
likoan [24]

Answer:

Answer explained with detail below

Explanation:

Consider the solution given by the greedy algorithm as a sequence of packages, here represented by indexes: 1, 2, 3, ... n. Each package i has a weight, w_i, and an assigned truck t_i. { t_i } is a non-decreasing sequence (as the k'th truck is sent out before anything is placed on the k+1'th truck). If t_n = m, that means our solution takes m trucks to send out the n packages.

If the greedy solution is non-optimal, then there exists another solution { t'_i }, with the same constraints, s.t. t'_n = m' < t_n = m.

Consider the optimal solution that matches the greedy solution as long as possible, so \for all i < k, t_i = t'_i, and t_k != t'_k.

t_k != t'_k => Either

1) t_k = 1 + t'_k

    i.e. the greedy solution switched trucks before the optimal solution.

    But the greedy solution only switches trucks when the current truck is full. Since t_i = t'_i i < k, the contents of the current truck after adding the k - 1'th package are identical for the greedy and the optimal solutions.

    So, if the greedy solution switched trucks, that means that the truck couldn't fit the k'th package, so the optimal solution must switch trucks as well.

    So this situation cannot arise.

  2) t'_k = 1 + t_k

     i.e. the optimal solution switches trucks before the greedy solution.

     Construct the sequence { t"_i } s.t.

       t"_i = t_i, i <= k

       t"_k = t'_i, i > k

     This is the same as the optimal solution, except package k has been moved from truck t'_k to truck (t'_k - 1). Truck t'_k cannot be overpacked, since it has one less packages than it did in the optimal solution, and truck (t'_k - 1)

     cannot be overpacked, since it has no more packages than it did in the greedy solution.

     So { t"_i } must be a valid solution. If k = n, then we may have decreased the number of trucks required, which is a contradiction of the optimality of { t'_i }. Otherwise, we did not increase the number of trucks, so we created an optimal solution that matches { t_i } longer than { t'_i } does, which is a contradiction of the definition of { t'_i }.

   So the greedy solution must be optimal.

6 0
2 years ago
Write a class for a Cat that is a subclass of Pet. In addition to a name and owner, a cat will have a breed and will say "meow"
fenix001 [56]

Answer:

The Java class is given below with appropriate tags for better understanding

Explanation:

public class Cat extends Pet{

  private String breed;

 public Cat(String name, String owner, String breed){

      /* implementation not shown */

      super(name, owner);

      this.breed = breed;

  }

  public String getBreed() {

      return breed;

  }

  public void setBreed(String breed) {

      this.breed = breed;

  }

  public String speak(){ /* implementation not shown */  

      return "Purring…";

  }

}

8 0
1 year ago
Compare the elements of the basic Software Development Life Cycle with 2 other models. How are they similar? How are they differ
Artemon [7]

Answer:

Explanation:

One of the basic notions of the software development process is SDLC models which stands for Software Development Life Cycle models. SDLC – is a continuous process, which starts from the moment, when it’s made a decision to launch the project, and it ends at the moment of its full remove from the exploitation. There is no one single SDLC model. They are divided into main groups, each with its features and weaknesses. The most used, popular and important SDLC models are given below:

1. Waterfall model

2. Iterative model

3. Spiral model

4. V-shaped model

5. Agile model

Stage 1. Planning and requirement analysis

Each software development life cycle model starts with the analysis, in which the stakeholders of the process discuss the requirements for the final product.

Stage 2. Designing project architecture

At the second phase of the software development life cycle, the developers are actually designing the architecture. All the different technical questions that may appear on this stage are discussed by all the stakeholders, including the customer.  

Stage 3. Development and programming

After the requirements approved, the process goes to the next stage – actual development. Programmers start here with the source code writing while keeping in mind previously defined requirements. The programming by itself assumes four stages

• Algorithm development

• Source code writing

• Compilation

• Testing and debugging

Stage 4. Testing

The testing phase includes the debugging process. All the code flaws missed during the development are detected here, documented, and passed back to the developers to fix.  

Stage 5. Deployment

When the program is finalized and has no critical issues – it is time to launch it for the end users.  

SDLC MODELS

Waterfall – is a cascade SDLC model, in which development process looks like the flow, moving step by step through the phases of analysis, projecting, realization, testing, implementation, and support. This SDLC model includes gradual execution of every stage completely. This process is strictly documented and predefined with features expected to every phase of this software development life cycle model.

ADVANTAGES  

Simple to use and understand

DISADVANTAGES

The software is ready only after the last stage is over

ADVANTAGES

Management simplicity thanks to its rigidity: every phase has a defined result and process review

DISADVANTAGES

High risks and uncertainty

Iterative SDLC Model

The Iterative SDLC model does not need the full list of requirements before the project starts. The development process may start with the requirements to the functional part, which can be expanded later.  

ADVANTAGES                                        

Some functions can be quickly be developed at the beginning of the development lifecycle

DISADVANTAGES

Iterative model requires more resources than the waterfall model

The paralleled development can be applied Constant management is required

Spiral SDLC Model

Spiral model – is SDLC model, which combines architecture and prototyping by stages. It is a combination of the Iterative and Waterfall SDLC models with the significant accent on the risk analysis.

4 0
1 year ago
Other questions:
  • Where is the Name Manager dialog box found?
    13·1 answer
  • Respond to the following in a paragraph of no less than 125 words. Describe the steps to active listening.
    7·2 answers
  • Write a program that allows you to create a file of customers for a company. The first part of the program should create an empt
    12·1 answer
  • Write a algorithm to attend birthday party​
    8·2 answers
  • Together with some anthropologists, you’re studying a sparsely populated region of a rainforest, where 50 farmers live along a 5
    15·1 answer
  • Lyrics = ["I wanna be your endgame", "I wanna be your first string",
    5·1 answer
  • What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
    6·1 answer
  • Warm colors including red, yellow and orange _____________ be energetic and exciting to the eye, while cool colors in blue, gree
    11·1 answer
  • Within a word processing program, predesigned files that have layout and some page elements already completed are called text bo
    15·1 answer
  • Which of the following could NOT be represented by a boolean variable?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!