In this post, we will see Java program to count positive, zero and negative numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.