• + 0 comments

    Language: JAVA 15

    In this problem We have to print the ratios of positive, negative and zero values with 6 digits after the decimal. To solve this problem I used printf() with format specifier

        public static void plusMinus(List<Integer> arr) {
        
        double positive=0;
        double negative=0;
        double zero=0;
    
        for(int i : arr){
            if(i>0){
                positive++;
            }
            else if(i<0){
                negative++;
            }
            else {
                zero++;
            }
            
        }
        
        System.out.printf("%.6f", positive/arr.size());
        System.out.println();
        System.out.printf("%.6f", negative/arr.size());
        System.out.println();
        System.out.printf("%.6f", zero/arr.size());
        
        }