Untitled
unknown
plain_text
3 years ago
1.0 kB
5
Indexable
public class Kata {
public static int[] countPositivesSumNegatives(int[] input) {
if (input == null || input.length == 0) {
return new int[0]; // Return an empty array if the input is null or empty
}
int countPositives = 0;
int sumNegatives = 0;
for (int number : input) {
if (number > 0) {
countPositives++;
} else if (number < 0) {
sumNegatives += number;
}
}
int[] result = new int[2];
result[0] = countPositives;
result[1] = sumNegatives;
return result;
}
public static void main(String[] args) {
int[] input = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15};
int[] result = countPositivesSumNegatives(input);
System.out.println("Count of positives: " + result[0]);
System.out.println("Sum of negatives: " + result[1]);
}
}
Editor is loading...