## Ant695

The idea is to write a program that asks a user for 10 numbers and then displays how many positive and negative numbers were entered. Not really sure where I'm going wrong but this was an extra assignment to kill time while everyone else catches up.

this is what I have so far.

``````/*Practica1 12 - Question 1
Program to ask a user to enter 10 numbers and display how many are positive and how many are negative
15/4/15*/

import java.util.*;
public class Positve_Negative
{
public static void main(String args[])
{
Scanner keyboardIn = new Scanner(System.in);
int Number;
int Positive = 0;
int Negative = 0;
int loop_start = 0;
int loop_end = 10;

for (loop_start < loop_end)
{
System.out.print ("Enter a number");
Number = keyboardIn.nextInt();
if ( Number >=0)
{
Positive ++;
}
else if ( Number <0)
{
Negative ++;
}
loop_start ++;
else
{
System.out.print ("Positive numbers were " + Positive + "& negative numbers were " + Negative);
}
}
}
}
``````

## DaveAmour 160

Delete Line 30, 31 and 33

Move Line 32 to after your loop

Change "else if ( Number <0)" to "else" - no need to check as it must be less than 0

## stultuske 1,092

a small remark, to make it easier:

``````...
int loop_end = 10;
for (loop_start < loop_end)
{
System.out.print ("Enter a number");
Number = keyboardIn.nextInt();
if ( Number >=0)
{
Positive ++;
}
loop_start ++;

}

System.out.print ("Positive numbers were " + Positive + "& negative numbers were " + (loop_end - Positive));
``````

there is no need for the negative variable, since you can derive it from the values of loop_end and Positive.

I would recommend, for future reference, to follow naming conventions. It will make it a lot easier for other people to read and understand your code.

## JamesCherrill 3,661

What about zeros? Zero isn't positive or negative?

## DaveAmour 160

Whether zero is positive, negative or neither is outside the scope of this question.

## stultuske 1,092

according to the original code posted, the OP considered it in the positive range.

## DaveAmour 160

The question is really about if statements and counters.

We could be counting bananas instead.

The questions of whether zero is positive or negative or neither has already been dealt with by mathematicians.