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
charle [14.2K]
3 years 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]3 years 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
Under extreme programming, ________ and ________ are intimately related parts of the same process
Inessa05 [86]
The answer to this question is: coding and testing
Extreme programming is a software development methodology that aim to improve software quality by measuring whether the technology can be used to fulfill customer's requirement.
To actually get somethings that is accepted by the customers, various coding and testing the software will be done constantly
8 0
3 years ago
Read 2 more answers
Write a C++ function for the following:
Nana76 [90]

Solution :

class Account

$ \{ $

public:

$\text{Account}()$;

double $\text{getBalance}$();

void $\text{setBalance}$();

$\text{bool withdraw}$(double bal);

$\text{private}:$

double $\text{balance}$;

}:

$\text{Account}()$ {}

double $\text{getBalance}$()

$ \{ $

$\text{return balance}$;

}

void $\text{setBalance}$(double $\text{balance}$)

$ \{ $

this.$\text{balance}$ = $\text{balance}$;

}

$\text{boolean}$ withdraw($\text{double bal}$)

$ \{ $

if($\text{balance}$ >= bal)

$ \{ $

$\text{balance}$ = $\text{balance}$ - bal;

$\text{return}$ true;

}

$\text{return}$ false;

}

}

4 0
2 years ago
In most programming languages, the compiler carries a preprocessing step to determine if certain statements will compile. For in
MakcuM [25]

Answer:

See explaination for program code

Explanation:

package com.company;

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.Stack;

/*

* A program which reads input from given text filename and prints

* whether it passed the pre-processing stage or not

* Sample input

* int A = (a + b);static void display(int x)

* {

* //A sample input file

* }

* */

public class MyPreprocessor {

/*

* Reads input from filename and returns a string

* containing whole text

* */

public String readInput(String filename) {

String content = "";

try {

content = new String(Files.readAllBytes(Paths.get(filename)));

} catch (IOException e) {

e.printStackTrace();

}

return content;

}

/**

* Filters input since we are only concerned with

* a subset of input = '{}[]()/*'

*/

public String filterText(String text) {

String output = "";

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

switch (text.charAt(i)) {

case '[':

case ']':

case '{':

case '}':

case '(':

case ')':

case '*':

case '/':

output += text.charAt(i);

}

}

return output;

}

/*

* Uses stack to determine if input is valid or not

* */

public boolean parse(String input) {

Stack<Character> St = new Stack<Character>();

// '$' is special symbol to represent bottom of stack

St.push('$');

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

Character symbol = input.charAt(i);

if(St.peek().equals(getOpenSymbol(symbol)))

St.pop();

else St.push(symbol);

}

return St.peek() == '$';

}

private static Character getOpenSymbol(Character symbol) {

switch (symbol) {

case '}': return '{';

case ']': return '[';

case ')': return '(';

case '*': return '*';

case '/': return '/';

default: return ' ';

}

}

public static void main(String[] args) {

MyPreprocessor preprocessor = new MyPreprocessor();

String inputText = preprocessor.readInput("src/input.txt");

String filteredInput = preprocessor.filterText(inputText);

if(preprocessor.parse(filteredInput))

System.out.println("preprocessing passed.");

else System.out.println("preprocessing failed!");

}

}

6 0
3 years ago
What is the next line?
Evgen [1.6K]

Answer:3

Explanation: it’s 3

3 0
3 years ago
Read 2 more answers
Should spreadsheets be used to keep an address list for holiday cards?<br> YES<br> ONO<br> Hurry pls
kodGreya [7K]

Answer:

No

because spreadsheet is used for calculation not for writing address

5 0
1 year ago
Other questions:
  • Computer maker Dell realized the problems with keeping large inventories, especially because of the fast rate of obsolescence of
    7·1 answer
  • To create a formula in. . You would first click in one of the cells
    12·2 answers
  • Determine the number of bytes necessary to store an uncompressed binary image of size 4000 × 3000 pixels
    11·1 answer
  • A_______ to show the working of an object before it is built or made. A. Prototype b. Test c. Evaluation d. Plan
    10·1 answer
  • Do you know the energy unit question?
    10·1 answer
  • What is the purpose of a project overview?
    8·2 answers
  • PLS HELP WITH MY PYTHON HW ILL GIVE YOU BRAINLIEST
    12·1 answer
  • Which actions represent parody?
    5·1 answer
  • You want to add a caption to a table. which tab contains this option?.
    11·1 answer
  • 30 POINTS FOR THE CORRECT ANSWERS
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!