Getting wrong output While trying to check the validity of a triangle where condition is ** sum of two side should be greater then the third** on 3 random integers between 0 to 20. Below output suggest two sides are greater then the third but showing "Not a valid triangle".
fun main() {
var a = (Math.random() * 20).toInt()
var b = (Math.random() * 20).toInt()
var c = (Math.random() * 20).toInt()
var validTriangle = "length $a,$b,$c"
if (a + b > c && b + c > a && a + c > b) {
println("Valid Triangle")
} else {
println("Not a valid Triangle")
}
println(validTriangle)
The below output suggests sum of two side(13,6) should be > third side(4)
which is 19 so answer should be "valid triangle" but it is not showing that
Output:
Not a valid Triangle
length 13,6,4
Aucun commentaire:
Enregistrer un commentaire