15,902,922 members
See more:
```3 integer variables from the user ( a, b, c ) and find how many of them are negative numbers.

After finding out the total count of negative numbers, return the count.

for no negative numbers, count will be 0.```

This is time and spaces complexity.

```Constraints
-10^6<=a<=10^6
-10^6<=b<=10^6
-10^6<=c<=10^6```

What I have tried:

```public class Main {
static int printCount(int a, int b, int c){

int count =0;
for(int i=0; i<a || i<b || i<c; i++){
if(a<0 || b<0 || c<0){
count++;
}

}
return count;
}
}

public static void main(String[] args) throws Throwable {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(printCount(a, b, c));
}
}```
Posted
Updated 26-Dec-22 23:38pm

## Solution 1

Think about how you would do it manually: You would start with a count of zero, then look at the first number. If it was negative, you would add one to the count. Then you'd do the same for the second, then for the third.
After that, you'd have the count.

So why do you need a loop at all? What does it bring to the exercise?

Implement what you would do manually - the code is simple, and you always get the correct result!

CPallini 27-Dec-22 5:38am
5.
Richard MacCutchan 27-Dec-22 5:43am
I wonder whether the actual question is a little more complicated ...
OriginalGriff 27-Dec-22 6:21am
I suspect it is - but we can only work with what he types. :sigh:

## Solution 2

(As Griff suggested...) your code is completely wrong.
You are required to check the entered numbers individually and increment the counter if the number currently examinated is negative.
So first check `a`. Is it negative? If that is the case then increment the counter.
The same for `b` and `c`.

Only after writing such a (admittedly simple) piece of code then you might think, as improvement, to implement it using an array of inputs (iterating on them).