IT/안드로이드
Array , List 연습 코드
뚱냐리
2022. 4. 7. 16:55
반응형
하 ㅡㅡ
낮설다 코틀린 너란녀석... ㅜ_ㅜ~
fun main(args: Array<String>) {
//println("\nYour fortune is : ${getFortuneCookie()}")
var fortune: String
for ( i in 1..10 ) {
fortune = getFortuneCookie()
println("\nYour fortune is : $fortune")
if(fortune.contains("Take it easy")) break
}
}
fun getFortuneCookie(): String{
val Fortunes = listOf("You will have a great day!", //0
"Things will go well for you today", //1
"Enjoy a wonderful day of success", //2
"Be humble and all will turn out well", //3
"Today is a good day for exercising restraint", //4
"Take it easy and enjoy life!", //5
"Treasure your friends, because they are your greatest fortune." //6
)
print("\nEnter your birthday: ")
val birthday = readLine()?.toIntOrNull() ?: 2
return Fortunes[birthday.rem(Fortunes.size)]
}
getFortuneCookie() 는 String 값 return 해주고...
Fortune 에 list넣어서 ... birthday값 받아서 값에 해당하는 string 값 뿌려준다. 여기서 bday에 null 값 들어갈수도 있으니
toIntOrNull 로 null 값 확인..
10회 시도시 Take it easy 뿌리고 break..
얼마나 더 해야 익숙해질까..
C 고인물은 웁니다..
728x90
반응형