Plus Minus

  • + 0 comments

    Kotlin Solution:

    fun plusMinus(arr: Array<Int>): Unit {
        var zero: Double = 0.0
        var positive: Double = 0.0
        var negative: Double = 0.0
        
        for (n in arr){
            if (n > 0){
                positive++
            } else if (n <0){
                negative++
            } else {
                zero++
            }
        }
        println(String.format("%.6f", (positive / arr.size).toDouble()))
        println(String.format("%.6f", (negative / arr.size).toDouble()))
        println(String.format("%.6f", (zero / arr.size).toDouble()))
    }