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));
}
}