-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplusMinus.java
More file actions
36 lines (33 loc) · 951 Bytes
/
plusMinus.java
File metadata and controls
36 lines (33 loc) · 951 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
/*
* Author: Sreenath T V
* https://www.hackerrank.com/challenges/plus-minus
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class plusMinus {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int N;
Scanner kbd = new Scanner(System.in);
N = kbd.nextInt();
int arr[] = new int[N];
int cp = 0, cn = 0, cz = 0;
for (int i = 0; i < N; i++) {
arr[i] = kbd.nextInt();
if (arr[i] > 0) {
cp++;
} else if (arr[i] < 0) {
cn++;
} else {
cz++;
}
}
float total = N * 1.0f;
System.out.println(String.format("%.3f", (cp / total)));
System.out.println(String.format("%.3f", (cn / total)));
System.out.println(String.format("%.3f", (cz / total)));
}
}