Kotlin
xxxxxxxxxx
fun main(args: Array<String>) {
val a = 2.3
val b = 4
val c = 5.6
val root1: Double
val root2: Double
val output: String
val determinant = b * b - 4.0 * a * c
if (determinant > 0) {
root1 = (-b + Math.sqrt(determinant)) / (2 * a)
root2 = (-b - Math.sqrt(determinant)) / (2 * a)
output = "root1 = %.2f and root2 = %.2f".format(root1, root2)
}
else if (determinant == 0.0) {
root2 = -b / (2 * a)
root1 = root2
output = "root1 = root2 = %.2f;".format(root1)
}
else {
val realPart = -b / (2 * a)
val imaginaryPart = Math.sqrt(-determinant) / (2 * a)
output = "root1 = %.2f+%.2fi and root2 = %.2f-%.2fi".format(realPart, imaginaryPart, realPart, imaginaryPart)
}
println(output)
}
root1 = -0.87+1.30i and root2 = -0.87-1.30i
JavaScript - Vérifier si une chaîne commence et se termine par certains caractères
Python - Vérifier si un nombre est positif, négatif ou 0
Linux - Comment installer anc-api-tools
Java - Inverser un nombre
Linux - Comment installer curvedns
C - Trouver le plus grand nombre à l'aide de l'allocation de mémoire dynamique
C - Compter le nombre de chiffres dans un entier
Python - Chat I/O chat très facile
JavaScript - Compter le nombre de voyelles dans une chaîne
Kotlin - Calculer la puissance d'un nombre
C++ - Convertir un nombre binaire en décimal et vice-versa
Kotlin - Trouver la factorielle d'un nombre
Python - Comment trier un dictionnaire par valeur ?
Linux - Comment installer zlib1g-dev
C++ - Vérifier si un nombre est premier ou non
Kotlin - Calculer la somme des nombres naturels
JavaScript - Trouver la somme des nombres naturels
GoLang - Comment écrivez-vous des chaînes multilignes
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month