Problem Statement
You're given an array containing integer values. You need to print the fraction of count of positive numbers, negative numbers and zeroes to the total numbers. Print the value of the fractions correct to 3 decimal places.
Input Format
First line contains N , which is the size of the array.
Next line containsN integers A1,A2,A3,⋯,AN , separated by space.
Next line contains
Sample Input
6
-4 3 -9 0 4 1
Sample Output
0.500
0.333
0.167
Explanation
There are 3 positive numbers, 2 negative numbers and 1 zero in the array.
Fraction of the positive numbers, negative numbers and zeroes are36=0.500 , 26=0.333 and 16=0.167 respectively.
Fraction of the positive numbers, negative numbers and zeroes are
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {double negative=0;
double positive=0;
double zero=0;
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int [] arr=new int[n];
for(int m:arr)
{
m=scn.nextInt();
if(m==0)
{
zero++;
}
else if(m<0)
{
negative++;
}
else if(m>0)
{
positive++;
}
}
System.out.println(positive/n);
System.out.println(negative/n);
System.out.println(zero/n);
}
}