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
5 ответов
+ 2
время Ч ,
You could also do something like this
if(day>=0 && day<=6)
println(names[day])
else
println("Invalid day.")
+ 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
+ 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.")
}
0
1. Decide what?
2. Where's your code?
3. Which is your question?
0
I did this but, something is missing, a mistake