๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
728x90

์ „์ฒด ๊ธ€140

Kotlin์—์„œ ํ•จ์ˆ˜ ๋งŒ๋“ค๊ธฐ ๋ฐ ์‚ฌ์šฉํ•˜๊ธฐ mainํ•จ์ˆ˜๋Š” ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์‹œ์ž‘์ ์œผ๋กœ ์‚ฌ์šฉ ํ•จ์ˆ˜ ์ •์˜ fun ํ•จ์ˆ˜๋ช…() { } ๋ฐ˜ํ™˜๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ 1)Unit ๋ฐ˜ํ™˜ ์œ ํ˜• ์•„๋ฌด๊ฒƒ๋„ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ 2) String์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ์œ ํ˜• ํ•˜๋‚˜์˜ ํ•จ์ˆ˜๋Š” ์˜ค์ง ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋งŒ ๋ฐ˜ํ™˜ ๊ฐ€๋Šฅ ๋ ค fun main() { println(birthdayGreeting()) } fun birthdayGreeting(): String { val nameGreeting = "Happy Birthday, Rover!" val ageGreeting = "You are now 5 years old" return "$nameGreeting\n$ageGreeting" } birthdayGreeting ํ•จ์ˆ˜์— ๋งค๊ฐœ๋ณ€์ˆ˜ ์ถ”๊ฐ€ํ•˜๊ธฐ ํ•˜๋‚˜์˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ๋ณ€์ˆ˜์ด๋ฆ„๊ณผ ๋ฐ์ดํ„ฐ ์œ ํ˜•์œผ๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ, :(์ฝœ.. 2022. 11. 14.
4. Kotlin์—์„œ ๋ณ€์ˆ˜ ๋งŒ๋“ค๊ธฐ ๋ฐ ์‚ฌ์šฉํ•˜๊ธฐ ๋ณ€์ˆ˜: ๊ฐ’์ด ํฌํ•จ๋œ ์ƒ์ž ์ƒ์ž์—๋Š” ๋ผ๋ฒจ์ด ์žˆ๊ณ , ๋ผ๋ฒจ์€ ๋ณ€์ˆ˜์˜ ์ด๋ฆ„์ด๋‹ค. ๋ฐ์ดํ„ฐ ์œ ํ˜• String ํ…์Šคใ…ก Int ์ •์ˆ˜ Double ์‹ญ์ง„์ˆ˜ Fload ์‹ญ์ง„์ˆ˜(Double๋ณด๋‹ค ์ •๋ฐ€๋„๊ฐ€ ๋‚ฎ์Œ), ์ˆซ์ž ๋์— f ๋˜๋Š” F๊ฐ€ ์žˆ๋‹ค. Boolean true ๋˜๋Š” false ๊ฐ€๋Šฅํ•œ ๋‘ ๊ฐœ์˜ ๊ฐ’์ด ์žˆ์„ ๋•Œ๋งŒ ์ด ๋ฐ์ดํ„ฐ ์œ ํ˜•์„ ์‚ฌ์šฉํ•œ๋‹ค. ํ‘œํ˜„์‹ ๊ณผ ํ‘œํ˜„์‹์˜ ๊ฐ’ ํ‘œํ˜„์‹์€ ๋ณ€์ˆ˜, ํ•จ์ˆ˜ ํ˜ธ์ถœ๋“ฑ์œผ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ’์ด ์žˆ๋Š” ์ฝ”๋“œ์˜ ์ž‘์€ ๋‹จ์œ„๋ฅผ ๋งํ•จ count -> ํ‘œํ˜„์‹์€ count ๋ณ€์ˆ˜ ํ•˜๋‚˜๋กœ ๊ตฌ์„ฑ 2 -> ํ‘œํ˜„์‹์˜ ๊ฐ’ ์‹ค์Šต ๋‚ ์งœ String ํ• ์ผ String ํ•  ์ผ ์ถ”๊ฐ€ +๋Š” Boolean ํ•  ์ผ ์ œ๊ฑฐ x๋Š” Boolean ์ผ๊ธฐ ๋‚ด์šฉ ๋ณด์ด๊ธฐ Boolean ๋ณ€์ˆ˜ ์„ ์–ธ val count: Int = 2 val ์ด๋ฆ„ : ๋ฐ์ดํ„ฐ .. 2022. 11. 14.
4. ์•ˆ๋“œ๋กœ์ด๋“œ ์•ฑ ๊ฐœ๋ฐœ์„ ์œ„ํ•ด์„œ ๊ผญ ์•Œ์•„์•ผ ํ•  ์ฝ”ํ‹€๋ฆฐ ๋ฌธ๋ฒ•๊ณผ ์‚ฌ์šฉ๋ฒ• var myName= "ํ—ˆ์„ฑํ˜„" Log.d(TAG,"my name = $myName") myName ="ํ—ˆ์„ฑ" Log.d(TAG,"my name = $myName") val myAge =19 Log.d(TAG,"pi = $PI") //myAge = 17 //val์€ ์žฌ์ •์˜ํ•  ์ˆ˜ ์—†๋‹ค. val PI = 3.14 // ์ž…๋ ฅํ•ด๋‘๋ฉด ๋ฐ”๊ฟ€ ํ•„์š”๊ฐ€ ์—†๋‹ค. ๋ณ€์ˆ˜์— ์ €์žฅํ•ด๋‘๊ณ  ์‚ฌ์šฉํ•œ๋‹ค. //var๋กœ ์„ ์–ธํ•œ ๊ฒƒ์„ ๋ณ€์ˆ˜๋ผ๊ณ  ํ•œ๋‹ค. // val๋กœ ์„ ์–ธํ•œ ๊ฒƒ์„ ์ƒ์ˆ˜๋ผ๊ณ  ํ•œ๋‹ค. //์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์ง€๋ฉด val์ธ์ง€ var์ธ์ง€ ๊ตฌ๋ถ„ํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๊ธฐ ๋•Œ๋ฌธ์— ์ฃผ๋กœ ์ƒ์ˆ˜๋Š” ๋Œ€๋ฌธ์ž๋กœ ์ ๋Š”๋‹ค. 2022. 11. 14.
log์‚ฌ์šฉํ•˜๊ธฐ // ๋ฒ„ํŠผ ๋กœ๊ทธ๊ฐ€ ํด๋ฆญ๋˜๋ฉด ๋กœ๊ทธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. buttonLog.setOnClickListener{ Log.d(TAG,"Hello Kotlin!!") } 2022. 11. 14.
728x90