As titled.
I’m working on a problem that requires me to find the max value of a Double 1D Array and have tried max()
but doesn’t work. Hoping someone would know how to do it
As titled.
I’m working on a problem that requires me to find the max value of a Double 1D Array and have tried max()
but doesn’t work. Hoping someone would know how to do it
It should be working correctly. Try editing this example:
fun main() {
println(arrayOf(1.0, 1.5, 2.5, 2.0, 8.0, 2.0, 1.0, 0.0, -5.0, 78.0).max())
}
If you really wanna do it yourself though, this should work:
fun main() {
val dobArray = arrayOf(1.0, 1.5, 2.5, 2.0, 8.0, 2.0, 1.0, 0.0, -5.0, 78.0)
var maximumValue: Double = Double.MIN_VALUE
for(i in dobArray){
maximumValue = if(i > maximumValue) i else maximumValue
}
println(maximumValue)
}
it ended up working, thank you