kotlin question Array ...... | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

kotlin question Array ......

Day of the Week The given program declares an array of weekday names. You need to take a number as input and output the name of the day at that index. In case the input is out of the range, output "Invalid day". Sample Input: 2 Sample Output: Tuesday here is my Answer fun main(args: Array<String>) { val names = arrayOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") val day = readLine()!!.toInt() if (day >= 0) { println(names[day]) } } it passed all the test except the Fifth Test...... please help me to fix this ........

1st May 2021, 9:34 AM
Abhishek Biswas
Abhishek Biswas - avatar
2 ответов
+ 4
Hi! you don't have a valid input check for a given range, and what should your program output if the data is out of bounds? read the task carefully again
1st May 2021, 10:38 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
#try this: fun main(args: Array<String>) { val names = arrayOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") var day = readLine()!!.toInt() if(day <= 6 && day >= 0) { println(names[day]) } else { println("Invalid day") } }
31st Oct 2021, 2:12 PM
Oussama Merroun
Oussama Merroun - avatar