In this post, we will see Java program to count positive, zero and negative numbers
import java.util.Scanner;
public class JavaProgram
{
public static void main(String args[])
{
int contp=0, cntn=0, cntz=0, i;
int arr[] = new int[10];
Scanner scan = new Scanner(System.in);
System.out.print("Enter 10 Numbers : ");
for(i=0; i<10; i++){
arr[i] = scan.nextInt();
}
for(i=0; i<10; i++){
if(arr[i] < 0){
cntn++;
}else if(arr[i] == 0){
cntz++;
}else{
contp++;
}
}
System.out.print(contp + " Positive Numbers");
System.out.print("\n" + cntn + " Negative Numbers");
System.out.print("\n" + cntz + " Zero");
}
}
Output:
Enter 10 Numbers : 10 0 45 -10 67 0 76 -33 64 -92
5 Positive Numbers
3 Negative Numbers
2 Zero
5 Positive Numbers
3 Negative Numbers
2 Zero
That’s all about Java program to count positive, zero and negative numbers