I'm just starting with Kotlin. This code doesn't give off errors. But I don't get the output I need. The else if statement seems to get no effect, even if I don't enter any character in the field. What did I do wrong?
fun main(){
print("Enter First Name: ")
var firstname: String? = readLine()
print("Enter Last Name: ")
var lastname: String? = readLine()
print("Prefix (Ms/Mr/Mrs)?: ")
var prefix: String? = readLine()
if (prefix!!.contains(".")){
prefix = prefix.substring(0,prefix.length-1)
}
if (firstname!!.isNotEmpty() && lastname!!.isNotEmpty() && prefix.length != 0) {
println(Applicant(firstname,lastname,prefix).message)
}
else
if (firstname == "\n"){
println("The First Name field is empty. Re-run the program to try again.")
}
if (lastname == "\n"){
println("The Last Name field is empty. Re-run the program to try again.")}
}
Aucun commentaire:
Enregistrer un commentaire