Plus Minus

  • + 0 comments

    **JAVA **

    int length = arr.size(); int countPositive = 0; int countNegative = 0; int countZeroes = 0;

    for(int i : arr){
        if(i > 0){
            countPositive++;
        } else if(i < 0){
            countNegative++;
        } else{
            countZeroes++;
        }
    }
    
        double positiveRatio = (double) countPositive / length;
        double negativeRatio = (double) countNegative / length;
        double zeroRatio = (double) countZeroes / length;
    
        System.out.println(String.format("%.6f", positiveRatio));
        System.out.println(String.format("%.6f", negativeRatio));
        System.out.println(String.format("%.6f", zeroRatio));