Plus Minus

  • + 1 comment

    Java streams

    public static void plusMinus(List<Integer> arr) {
    
        long negValues = arr.stream().filter(x -> x < 0).count();
        long posValues = arr.stream().filter(x -> x > 0).count();
        long zeroValues = arr.stream().filter(x -> x == 0).count();
        long length = negValues + posValues + zeroValues;
        
        
        System.out.println((double)posValues/length);
        System.out.println((double)negValues/length);
        System.out.println((double)zeroValues/length);
    
        }