Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hypotenuse of triangle Kotlin

Okay, pretty sure I got my formula right… don’t think I quite understand how to call on methods, howcome mine isn’t working?

    fun main() {
    println("Enter Width of the triangle")
    readln()
    println("Enter Height of the triangle")
    ComputeMethods().hypotenuse(readln().toDouble())
}

 class ComputeMethods(){
fun hypotenuse(width: Int, height: Int) {
    val triangle = width.toDouble().pow(2) + height.toDouble().pow(2)
    val formula = "$triangle"
    println(formula)
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Gilli, Here is the working code example for triangle formula, You have to pass input arguments in space separated format (2.0 3.0), You can interact with the link given https://pl.kotl.in/mq-8jgVRy in order to run the program on kotlin playground.

import kotlin.math.pow

fun main(args: Array<String>) {
    println("Enter Width of the triangle")
    val width = args[0].toDouble()
    println("Enter Height of the triangle")
    val height = args[1].toDouble()
    ComputeMethods().hypotenuse(width, height)
}

class ComputeMethods(){
fun hypotenuse(width: Double, height: Double) {
    val triangle = width.pow(2) + height.pow(2)
    val formula = "$triangle"
    println(formula)
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading