Skip to content

Commit 0368859

Browse files
authored
Create PlusMinus.java
1 parent 13e4e0a commit 0368859

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

PlusMinus.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
3+
import java.io.*;
4+
import java.math.*;
5+
import java.security.*;
6+
import java.text.*;
7+
import java.util.*;
8+
import java.util.concurrent.*;
9+
import java.util.function.*;
10+
import java.util.regex.*;
11+
import java.util.stream.*;
12+
import static java.util.stream.Collectors.joining;
13+
import static java.util.stream.Collectors.toList;
14+
15+
class Result
16+
{
17+
/*
18+
* Complete the 'plusMinus' function below.
19+
*
20+
* The function accepts INTEGER_ARRAY arr as parameter.
21+
*/
22+
23+
public static void plusMinus(List<Integer> arr)
24+
{
25+
// Write your code here
26+
int n = arr.size();
27+
int positiveNumbers = 0;
28+
int negativeNumbers = 0;
29+
int zeroNumbers = 0;
30+
31+
for(int arrElement : arr)
32+
{
33+
if(arrElement > 0)
34+
{
35+
positiveNumbers++;
36+
}
37+
38+
else if(arrElement < 0)
39+
{
40+
negativeNumbers++;
41+
}
42+
43+
else
44+
{
45+
zeroNumbers++;
46+
}
47+
}
48+
49+
double positiveNumbersRatio = (double) positiveNumbers / n;
50+
double negativeNumbersRatio = (double) negativeNumbers / n;
51+
double zeroNumbersRatio = (double) zeroNumbers / n;
52+
53+
System.out.printf("%.6f%n", positiveNumbersRatio);
54+
System.out.printf("%.6f%n", negativeNumbersRatio);
55+
System.out.printf("%.6f%n", zeroNumbersRatio);
56+
}
57+
}
58+
59+
public class PlusMinus
60+
{
61+
public static void main(String[] args) throws IOException
62+
{
63+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
64+
65+
int n = Integer.parseInt(bufferedReader.readLine().trim());
66+
67+
List<Integer> arr = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
68+
.map(Integer::parseInt)
69+
.collect(toList());
70+
71+
Result.plusMinus(arr);
72+
73+
bufferedReader.close();
74+
}
75+
}

0 commit comments

Comments
 (0)