-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI054.java
More file actions
39 lines (37 loc) · 1.52 KB
/
I054.java
File metadata and controls
39 lines (37 loc) · 1.52 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
package levelB;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class I054 {
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int N=Integer.parseInt(br.readLine());
String[] str=br.readLine().split(" ");
ArrayList<Double> list=new ArrayList<>();
double sum=0;
for(int i=0;i<str.length;i++){
try{
double temp=Double.parseDouble(str[i]);
if(temp<-1000||temp>1000){
System.out.println("ERROR: "+str[i]+" is not a legal number");
continue;
}
double compare=Math.round(temp*100)*1.0/100;//Double.parseDouble(String.format("%.2f",temp))
if(temp!=compare){
System.out.println("ERROR: "+str[i]+" is not a legal number");
continue;
}
sum+=temp;
list.add(temp);
}catch (Exception e){
System.out.println("ERROR: "+str[i]+" is not a legal number");
}
}
if(list.size()==0)
System.out.println("The average of 0 numbers is Undefined");
else if(list.size()==1)
System.out.printf("The average of 1 number is %.2f",sum);
else
System.out.printf("The average of "+list.size()+" numbers is %.2f",sum/list.size());
}
}