by Dinesh Thakur Category: Control Structures

In this example we use BufferedReader class for Reading text from a character-input stream. After Enter any 5 Number we check if number ==0 then is zero if number greater than 0 then it is positive other wise negative.

Here is the Java Example for Enter 10 Number and Print the Number of Positive, Negative and Zeros Number:

import java.io.*;

class PosNegZer
{
            public static void main(String args[] )
            throws IOException
            {
                   BufferedReader PosNeg = new BufferedReader(new InputStreamReader(System.in));
                        String m;
                        int n,Pos, Neg, Zer,i;
                        Pos=Neg=Zer=0;
                        System.out.println("Enter any 5 Number ");
                        for(i=1;i<=5;i++)
                        {
                                    m=PosNeg.readLine();
                                    n=Integer.parseInt(m);
                                    if(n==0)Zer++;
                                    if(n<0)Neg++;
                                    if(n>0)Pos++;
                        }
                        System.out.println("The Positive Numbers are : "+Pos);
                        System.out.println("The Negative Numbers are : "+Neg);
                        System.out.println("The Zero Values are : "+Zer);
            }
}

Number of Positive, Negative and Zeros Number

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article