forked from chennakrishnans/JAVA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpositive.java
More file actions
40 lines (39 loc) · 820 Bytes
/
Copy pathpositive.java
File metadata and controls
40 lines (39 loc) · 820 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
31
32
33
34
35
36
37
38
39
40
import java.util.*;
class positive
{
public static void main(String[] args)
{
try
{
Scanner input = new Scanner(System.in);
float pos = 0,neg = 0,num=0,p=0,n=0;
while(num!=-1)
{
System.out.print("enter the number:- ");
num = input.nextInt();
if(num>0)
{
pos++;
p=p+num;
}
else if(num<0)
{
neg++;
n=n+num;
}
}
System.out.println("the no.of.negative values are "+neg);
System.out.println("the no.of.positive values are "+pos);
System.out.println("the sum of positive values "+p);
System.out.println("the sum of negative values"+n);
float p1=p/pos;
float p2=n/neg;
System.out.println("avg of positive numbers"+p1);
System.out.println(" avg of negative numbers"+p2);
}
catch(Exception e)
{
System.out.println("Enter a valid number");
}
}
}