์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- androidx
- Linux
- ์ข์๊ธํ์ฌํ๊ธฐ
- ๋ช ์ฌ๋ณด๊ฐ
- Android
- Coroutine
- kotlin
- ํ์ด์ฌ
- ๋ช ์ธ๋ชจ์
- ASMR
- ๊ณต๋ถ์ง์ค
- Freesound
- ์ด๋ชจ์ง๋ฉ๋ชจ
- bash
- recyclerview
- ์ด๋ชจ์ง
- jetpack compose
- Flutter
- FSM
- Firebase
- ๋ฒค์๋ฏผํ๋ญํด๋ฆฐ
- ์คํ์์ค
- ๊ณต์๋ช ์ธ
- ๋ทํ๋ฆญ์ค
- ์์ธ์นผ๋ฆฌ๋ฒ6
- ์ฅ์๋ช ์ธ
- DART
- 1์ธ๊ฐ๋ฐ์
- ์ฝํ๋ฆฐ
- Streaming
Archives
- Today
- Total
Vintage appMaker์ Tech Blog
[kotlin] associate๋ฅผ ์ด์ฉํ list → Map ๋ณธ๋ฌธ
Source code or Tip/Android(Java, Kotlin)
[kotlin] associate๋ฅผ ์ด์ฉํ list → Map
VintageappMaker 2020. 12. 29. 11:32๐ข ๋ฆฌ์คํธํํ์ ๋ฐ์ดํฐ๋ฅผ map ํํ๋ก ๋ณํํ ๋ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๋ฉ์๋์ด๋ค.
fun main(args: Array<String>) {
// ์์ฐจ์ ์ธ ๊ฐ์ ๊ธฐ์ค์ผ๋ก map ์์ฑ
val player_reward = (1..100).associate{
it to reward(it)
}
(1..50).forEach { println ("${it}๋ฑ -> ${player_reward[it]}") }
}
fun reward(n: Int, baseMoney : Int = 1000): Int =
// if else์ ๊ฐ์ํ ๋ชฉ์
when {
n == 1 -> baseMoney * 10
n in 2..3 -> baseMoney * 5
n in 4..10 -> baseMoney * 2
else -> baseMoney
}
'Source code or Tip > Android(Java, Kotlin)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[kotlin] sealed class์ ๋์ฒดํฌ๋ฅผ ์ํ Elvis ์ฐ์ฐ์ (0) | 2021.01.06 |
---|---|
Newsletter - kotlin, Android (0) | 2021.01.01 |
Android ์ฑ์ ์ฟ ํกํํธ๋ ๋ฐฐ๋๋ฌ๊ธฐ (0) | 2020.12.25 |
Android App shortcut ๋ง๋ค๊ธฐ (0) | 2020.12.24 |
kotlin์์ xml์ ID๋ก ๋ณ์๋ฅผ ์๋์ผ๋ก ์ฝ์ด์ค์ง ๋ชปํ ๋ (0) | 2020.12.22 |
Comments