# Counting positive number inputs and negative number inputs of user. HELP!

• 10-24-2012, 11:03 AM
cs3
Counting positive number inputs and negative number inputs of user. HELP!
My program reads a number input of the user until '0' is given. My code is fine until I ask the program to count how many times they input a positive number and how many times they input a negative number.
Code:

```import java.util.Scanner; public class NumberLab4 {         public static void main(String[] args)         {                 Scanner input = new Scanner (System.in);                 System.out.print ("Please enter a number (0 to terminate): ");                                 int count, numofinput = 0;                 count = input.nextInt();                                                 while (count != 0)                 {                         if (count != 0)                                 System.out.print ("Please enter another number (0 to terminate): ");                                         numofinput++;                                         count = input.nextInt();                                }                 if (count == 0);                         System.out.println ("Program terminated.");                                 if (numofinput > 0)                                 System.out.println ("Number of positive numbers entered: " + numofinput);                         if (numofinput < 0)                                 System.out.println ("Number of negative numbers entered: " + numofinput);                                 System.out.println ();                         }                        }```
• 10-24-2012, 01:21 PM
JBelg
Re: Counting positive number inputs and negative number inputs of user. HELP!
The problem is because you're not differentiating between negative and positive numbers.

Something like this
Code:

```import java.util.Scanner; public class NumberLab4 {     public static void main(String[] args)     {         Scanner input = new Scanner (System.in);         System.out.print ("Please enter a number (0 to terminate): ");                 int inputNr, negNr = 0, posNr = 0;         inputNr = input.nextInt();                         while (inputNr != 0)         {             if (inputNr > 0)                 posNr++;             else                 negNr++;             System.out.print ("Please enter another number (0 to terminate): ");             input = input.nextInt();                }             System.out.println ("Program terminated.");                     System.out.println ("Number of positive numbers entered: " + posNr);                 System.out.println ("Number of negative numbers entered: " + negNr);             }          }```