-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaArrays_Set1.java
More file actions
92 lines (56 loc) · 1.45 KB
/
JavaArrays_Set1.java
File metadata and controls
92 lines (56 loc) · 1.45 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class JavaArrays_Set1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int testcases = 0;
int NumberN = 0;
List<Long> numbers = new ArrayList<Long>();
List<String> OT = new ArrayList<String>();
//ArrayList<Long> numbers = new ArrayList<Long>();
Scanner sc = new Scanner(System.in);
testcases = sc.nextInt();
if(testcases >= 1 && testcases <=100) {
for(int i = 0;i<testcases;i++) {
NumberN = (int) sc.nextLong();
if(NumberN >= 1 && NumberN <=100) {
for(int j=0; j<NumberN;j++) {
numbers.add(j, sc.nextLong());
}
OT.add(i, calculateAvgSum(numbers));
}
}
for(int i = 0; i<OT.size() ; i++) {
System.out.println(OT.get(i));
}
}
else {
System.exit(0);
}
}
private static String calculateAvgSum(List<Long> numbers) {
// TODO Auto-generated method stub
String out = "";
int lenght = numbers.size();
int summ = 0;
double avg;
DecimalFormat f = new DecimalFormat("##.00");
for(int k=0; k<lenght;k++) {
summ += numbers.get(k);
}
avg = (double) summ/lenght;
f.format(avg);
out = summ + " " + f.format(avg);
return out;
//System.out.println(out);
/*
*
1
9
2 55 85 656 52 554 545 5 2
*/
}
}