Plus Minus

  • + 0 comments
        public static void plusMinus(List<Integer> arr) {
            // Write your code here
            
            int positiveRatio = 0;
            int negativeRatio = 0;
            int zerosRatio = 0;
            
            int length = arr.size();
            
            for(int num: arr){
                if(num == 0){
                    zerosRatio += 1;
                }else if(num > 0){
                    positiveRatio += 1;
                }else{
                    negativeRatio += 1; 
                }
            }
        
            System.out.printf("%.6f%n", (double) positiveRatio / length);
            System.out.printf("%.6f%n", (double) negativeRatio / length);
            System.out.printf("%.6f%n", (double) zerosRatio / length);
        }