-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram28.java
More file actions
30 lines (26 loc) · 776 Bytes
/
Copy pathprogram28.java
File metadata and controls
30 lines (26 loc) · 776 Bytes
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
// Count how many positive, negative, and zero values exist in array.
public class program28 {
public static void main(String[] args) {
int arr[] = {2,3,6,0,-5,0,12};
System.out.print("Array Elements : ");
for(int i=0; i<arr.length; i++){
System.out.print(arr[i] + " ");
}
int p =0;
int n =0;
int z =0;
for(int i =0; i<arr.length; i++){
if(arr[i]>0){
p++;
}else if(arr[i]<0)
n++;
else{
z++;
}
}
System.out.println();
System.out.println("Positive : " + p);
System.out.println("Negative : " + n);
System.out.println("Zero : " + z);
}
}