0

help me decide

This program is an array with the names of the days of the week. You need to take a number as input and return the name of the day given the index of the index. If the input data is outside of the possible opening, the program should display "Invalid day". Example Input: 2 Example Output: Tuesday

25th Jan 2022, 11:24 PM
время Ч
5 Antworten
+ 2
время Ч , You could also do something like this if(day>=0 && day<=6) println(names[day]) else println("Invalid day.")
26th Jan 2022, 1:07 AM
SoloProg
SoloProg - avatar
+ 2
enum class Day() { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday } fun main(args: Array<String>) { val n: Int = readLine()!!.toInt() val d: Day? = Day.values().getOrNull(n) // Default to null if (d==null) print("Invalid day") else print(d) } https://code.sololearn.com/c5cobB1av6OO
26th Jan 2022, 1:00 AM
SoloProg
SoloProg - avatar
+ 1
fun main(args: Array<String>) { val names = arrayOf("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") var day = readLine()!!.toInt() if(day=0 && day<6){ println(names[]) } else(day>6) println("Invalid day.") }
26th Jan 2022, 12:50 AM
время Ч
0
1. Decide what? 2. Where's your code? 3. Which is your question?
26th Jan 2022, 12:31 AM
Emerson Prado
Emerson Prado - avatar
0
I did this but, something is missing, a mistake
26th Jan 2022, 1:14 AM
время Ч