Reputation: 13
I am Unable to use the .toChar()
in Kotlin after the readLine()!!
Like in This Case
//An Array Of Characters
var CharAr= Array<Char>(5){' '}
for(i in 0..4){
println("Please Enter The character Number ${i+1}")
CharAr[i]= readLine()!!.toChar()
}
Or Even In This Case
//Normal readLine()
var CharacterNum1:Char
println("Please Enter a Character")
CharacterNum1= readLine()!!.toChar()
Thank You For Your Help :)
Upvotes: 0
Views: 324
Reputation: 82027
readLine()
returns a String?
. This type does not have a toChar
method. What you can do is take the first char of that String
like this:
charAr[i] = readLine()?.get(0) ?: throw IllegalArgumentException()
Upvotes: 3