0

kotline program showing "Unhandled Exception: Input string was not in a correct format."

I don't know what's wrong with this code can anyone tell me why it's showing an error code: fun main(args: Array<String>) { var ComputersChoice="" var PlayerChoice="" var RandomNumber=(1..3).random() if(RandomNumber==1){ ComputersChoice="ROCK" }else if(RandomNumber==2){ ComputersChoice="PAPER" }else{ ComputersChoice="SCISSORS" } println("\nEnter Your Choice: ROCK,PAPER,or,SCISSORS") PlayerChoice=readln().uppercase() if(ComputersChoice==PlayerChoice) { println("it's Draw *----*") }else if(ComputersChoice=="ROCK" && PlayerChoice=="SCISSORS" || ComputersChoice=="PAPER" && PlayerChoice=="ROCK" || ComputersChoice=="SCISSORS" && PlayerChoice=="PAPER"){ println("You Lost -_-") }else{ println("You Won :)") } }

18th Oct 2024, 10:44 AM
Abhishek Shelar
Abhishek Shelar - avatar
3 ответов
+ 4
readLine() instead of readln()
18th Oct 2024, 11:18 AM
Lisa
Lisa - avatar
+ 2
Change your input line like this: PlayerChoice=readLine()?.uppercase() ?: ""
18th Oct 2024, 11:23 AM
Jerry Hobby
Jerry Hobby - avatar
+ 2
Sololearn does not recognize readln. Also, I added some more input validation and single character input for user convenience. https://sololearn.com/compiler-playground/cAzyMDR9CV4n/?ref=app
19th Oct 2024, 12:19 AM
Bob_Li
Bob_Li - avatar