© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
17 replies
Val, they/them

count positives and sum of negatives

hi, im doing an excercise that given an array of integers, I have to return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array.

i've been on this excercise for over 30 minutes but i cant figure out how to do the last step (If the input is an empty array or is null, return an empty array.) can someone help me out figuring out what im missing/ doing wrong?
=============
using System;
using System.Collections.Generic;
using System.Linq;

public class Kata
{
public static int[] CountPositivesSumNegatives(int[] input)
{
if ((input.Length == 0) || (input == null))
{
;
return new int [] {};
}
else{
int pos = 0;
int neg = 0;
foreach (int i in input)
{
if (i > 0)
{
pos += 1;
}
else if (i <= 0){
neg += i;
}
}
if ((pos == 0) && (neg == 0))
{
int [] result = {};

return result;
}
else{
int [] result = {pos, neg};
return result;
}
}
//return an array with count of positives and sum of negatives
}
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How to sum datetimeoffset and timespan?
C#CC# / help
3y ago
❔ Windows Defender false positives my application
C#CC# / help
3y ago
how to get sum of array's
C#CC# / help
3y ago
sum of all numbers in between [Answered]
C#CC# / help
4y ago