Skip to content

Commit 2d45ccf

Browse files
authoredOct 4, 2020
Added PlusMinus hackerrank problem
1 parent cbfadb5 commit 2d45ccf

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
12+
static void plusMinus(int[] arr) {
13+
14+
int dimension = arr.length;
15+
double positives = 0;
16+
double negatives = 0;
17+
double zeros = 0;
18+
19+
for (int i = 0; i < dimension; i++) {
20+
if (arr[i] > 0) {
21+
positives++;
22+
} else if (arr[i] < 0) {
23+
negatives++;
24+
} else {
25+
zeros++;
26+
}
27+
}
28+
29+
positives /= dimension;
30+
negatives /= dimension;
31+
zeros /= dimension;
32+
33+
System.out.printf("%.6f\n%.6f\n%.6f\n", positives, negatives, zeros);
34+
35+
}
36+
37+
private static final Scanner scanner = new Scanner(System.in);
38+
39+
public static void main(String[] args) {
40+
int n = scanner.nextInt();
41+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
42+
43+
int[] arr = new int[n];
44+
45+
String[] arrItems = scanner.nextLine().split(" ");
46+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
47+
48+
for (int i = 0; i < n; i++) {
49+
int arrItem = Integer.parseInt(arrItems[i]);
50+
arr[i] = arrItem;
51+
}
52+
53+
plusMinus(arr);
54+
55+
scanner.close();
56+
}
57+
}

0 commit comments

Comments
 (0)
Failed to load comments.