← Unit 4 · all exercises
Saved in this browser only

Count the negatives

Return how many numbers in the array are below zero.

int countNegatives(int[] values)

Solution.java
Loading editor…
Results

Examples

  • Solution.countNegatives(new int[]{-1, 2, -3}) → 2
  • Solution.countNegatives(new int[]{1, 2}) → 0

There are also 3 hidden tests you can't see. Solve the problem, not the examples.