Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,844 questions

55,671 answers

573 users

How to find the maximum value in a multidimensional array with Kotlin

1 Answer

0 votes
fun findMax(array: Array<Array<Double>>): Double {
    var maxValue = Double.MIN_VALUE // Initialize with the smallest possible Double value

    // Traverse the multidimensional array
    for (row in array) {
        for (value in row) {
            if (value > maxValue) {
                maxValue = value // Update maxValue if a larger value is found
            }
        }
    }

    return maxValue
}

fun main() {
    // Define a multidimensional array
    val array = arrayOf(
        arrayOf(1.0, 2.0,  3.14),
        arrayOf(1.0, 1.0, 16.80),
        arrayOf(3.0, 5.0, 17.50),
        arrayOf(2.0, 4.0, 11.03)
    )

    val maxValue = findMax(array)

    println("The maximum value in the array is: $maxValue")
}


   
      
/*
run:
   
The maximum value in the array is: 17.5
  
*/

 



answered Apr 6, 2025 by avibootz
...