-
Notifications
You must be signed in to change notification settings - Fork 858
Expand file tree
/
Copy pathPlusMinus.java
More file actions
42 lines (40 loc) · 971 Bytes
/
Copy pathPlusMinus.java
File metadata and controls
42 lines (40 loc) · 971 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
37
38
39
40
41
42
/**
*
* Problem Statement-
* [Plus Minus](https://www.hackerrank.com/challenges/plus-minus)
* [Tutorial](https://youtu.be/aLS4HYPfzUw)
*
*/
package com.javaaid.hackerrank.solutions.generalprogramming.basicprogramming;
import java.util.Scanner;
/**
*
* @author Kanahaiya Gupta
*
*/
public class PlusMinus {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[] = new int[n];
float countPositive = 0;
float countNegetive = 0;
float countZero = 0;
for (int arr_i = 0; arr_i < n; arr_i++) {
arr[arr_i] = in.nextInt();
if (arr[arr_i] < 0) {
countNegetive++;
}
if (arr[arr_i] > 0) {
countPositive++;
}
if (arr[arr_i] == 0) {
countZero++;
}
}
System.out.printf("%1.6f \n", countPositive / n);
System.out.printf("%1.6f \n", countNegetive / n);
System.out.printf("%1.6f \n", countZero / n);
in.close();
}
}