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
nikdorinn [45]
4 years ago
10

Create a static method called negToZero, which takes an integer array, and returns a new integer array in which all negative ent

ries in the input array have been changed to zero. The non-negative entries should remain unchanged. Example: theArray:{0,4,-6,-5,3} ==> {0,4,0,0,3} public static int [ ] negToZero (int [ ] theArray) {
Computers and Technology
1 answer:
postnew [5]4 years ago
5 0

Answer:

public static int[] negToZero(int [] theArray){

        int[] newArray = new int[theArray.length];

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

           if(theArray[i]>=0){

               newArray[i]=theArray[i];

           }else{

              newArray[i]=0;

           }

        }

        return newArray;

    }

Explanation:

The function is a block of the statement which performs the special task.

To return the array from the function, you have to define the function with return type array.

like, int[] name(parameter){

}

Then declare the new array with the same size.

Take the for loop for traversing in the array and check the condition for positive numbers by using if-else statement, if the value is positive store in the new array as it is. Otherwise, store the zero in the new array with the same position.

This process repeated until the condition in the for loop is true.

and finally, return the array.

You might be interested in
Which area located at the top of the word screen includes home , insert , and page layout ?
Misha Larkins [42]

Answer:

Whats your qeustion

Explanation:

4 0
3 years ago
Read 2 more answers
In this scenario, what is the importance of anti-virus software and other similar virus protection programs?
Svetradugi [14.3K]
To protect my computer form hacking and save my files
3 0
4 years ago
What is the recommended solution to configure this automated behavior? UC has a requirement that an opportunity should have a fi
Dmitry_Shevchenko [17]
The answer will need to be workflow.
8 0
4 years ago
These are keywords used with mysql_query/ mysqli_queryto update records in a table.
Brrunno [24]

Answer:

D.insert, into, values

3 0
3 years ago
Read 2 more answers
Lots of data can be transferred in short time, when we have,
dusya [7]

Answer: B. Higher Bandwidth

8 0
3 years ago
Read 2 more answers
Other questions:
  • If you’re storing some personal information like Debit/Credit card numbers or Passwords etc, on different sites for running you’
    10·1 answer
  • Define and test a function myRange. This function should behave like Python’s standard range function, with the required and opt
    11·2 answers
  • If you interview a dentist to learn about her experiences on the job, she is considered a secondary source of information. Pleas
    7·2 answers
  • (BRAINLIEST QUESTION) What are some challenges that will need to be overcome in order for the Internet of Vehicles to become a r
    13·1 answer
  • assume an int array, candy, stores the number of candy bars sold by a group of children wherecandy[j] is the number of candy bar
    7·2 answers
  • A computer has been stored, uncovered, in a dusty closet for several months. Why might this situation cause the operating system
    13·1 answer
  • The physical parts or components of a computer system is called?
    8·2 answers
  • Suppose an IP packet is fragmented into 10 fragments, each with a 1% (independent) probability of loss. To a reasonable approxim
    15·1 answer
  • Question 1 (3 points)
    6·2 answers
  • Hi, I am from India. Our brainly platform isn't so good, many of 'em keep spamming questions that I ask. US platform seems much
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!