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.