MCPcopy Create free account
hub / github.com/MohamedMetwalli5/HackerRank-Solutions / PlusMinus

Class PlusMinus

ProblemSolving (General)/PlusMinus.java:9–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7import java.util.regex.*;
8
9public class PlusMinus {
10
11 // Complete the plusMinus function below.
12 static void plusMinus(int[] arr) {
13 int positive = 0 , negative = 0 , zero = 0;
14 for(int i=0;i<arr.length;i++){
15 if(arr[i] == 0){
16 zero++;
17 }else if(arr[i] < 0){
18 negative++;
19 }else if(arr[i] > 0){
20 positive++;
21 }
22 }
23
24 System.out.println((double)positive/arr.length);
25 System.out.println((double)negative/arr.length);
26 System.out.println((double)zero/arr.length);
27
28 }
29
30 private static final Scanner scanner = new Scanner(System.in);
31
32 public static void main(String[] args) {
33 int n = scanner.nextInt();
34 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
35
36 int[] arr = new int[n];
37
38 String[] arrItems = scanner.nextLine().split(" ");
39 scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
40
41 for (int i = 0; i < n; i++) {
42 int arrItem = Integer.parseInt(arrItems[i]);
43 arr[i] = arrItem;
44 }
45
46 plusMinus(arr);
47
48 scanner.close();
49 }
50}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected