-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvenOddNumAverage.java
77 lines (49 loc) · 1.78 KB
/
EvenOddNumAverage.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Read inputSTDIN. Print your output to STDOUT*/
import java.util.*;
import java.io.*;
public class EvenOddNumAverage {
public static void mAverageFunction(double even,double odd,int totalEven,int totalOdd){
double averageEven,averageOdd;
averageEven=even/totalEven;
averageOdd=odd/totalOdd;
System.out.println("average Even :"+averageEven);
System.out.println("average Even :"+averageOdd);
double mSum=averageOdd+averageEven;
System.out.println("Sum of Both Average: "+mSum);
int mAverageSum=(int)Math.round(averageOdd+averageEven);
System.out.println("Sum of Both Average: "+mAverageSum);
}
public static void evenOddNumberFinder(double array[]){
int countEven=0;
int countOdd=0;
double mSumOdd=0;
double mSumEven=0;
// int i;
for(int i=0;i<array.length;i++){
if(array[i]%2==0){
mSumEven=mSumEven+array[i];
countEven++;
}
if(array[i]%2!=0){
mSumOdd=mSumOdd+array[i];
countOdd++;
}
}
System.out.println("Even "+"Sum : "+mSumEven+" Count :" +countEven);
System.out.println("Odd "+"Sum : "+mSumOdd+" Count :" +countOdd);
mAverageFunction(mSumEven,mSumOdd,countEven,countOdd);
}
public static void main(String args[] ) throws Exception {
//Write code here
int i;
Scanner sc=new Scanner(System.in);
System.out.print("Size :");
int mSize=sc.nextInt();
System.out.print("Values :");
double[] Array=new double[mSize];
for(i=0;i<Array.length;i++){
Array[i]=sc.nextDouble();
}
evenOddNumberFinder(Array);
}
}