๊ด€๋ฆฌ ๋ฉ”๋‰ด

ruriruriya

[Android Kotlin] ์•ˆ๋“œ๋กœ์ด๋“œ ์ฝ”ํ‹€๋ฆฐ - ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ ๋ณธ๋ฌธ

๐Ÿค–Android/Kotlin

[Android Kotlin] ์•ˆ๋“œ๋กœ์ด๋“œ ์ฝ”ํ‹€๋ฆฐ - ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ

๋ฃจ๋ฆฌ์•ผใ…‘ 2024. 10. 12. 08:48
๋ฐ˜์‘ํ˜•

์ฝ”ํ‹€๋ฆฐ์—์„œ๋Š” ๋ฌธ์ž์—ด ์•ˆ์— ๋ณ€์ˆ˜๋‚˜ ํ‘œํ˜„์‹์„ ๊ฐ„ํŽธํ•˜๊ฒŒ ์‚ฝ์ž…ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ์ด ์žˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์‰ฝ๊ฒŒ ๋ฌธ์ž์—ด์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๊ณ  ๋˜ํ•œ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ๋„ ์ข‹์•„์ง„๋‹ค.

1. ๋ณ€์ˆ˜๋ฅผ ๋ฌธ์ž์—ด์— ์‚ฝ์ž…

๋ฌธ์ž์—ด์— ๋ณ€์ˆ˜๋ฅผ ๋„ฃ๊ณ  ์‹ถ์„ ๋•Œ, ๋ณ€์ˆ˜ ์•ž์— $ ๊ธฐํ˜ธ๋ฅผ ๋ถ™์ธ๋‹ค.

val name = "Alice"
val age = 25

// ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•œ ์˜ˆ์‹œ
val greeting = "Hello, my name is $name and I am $age years old."

println(greeting)  // ์ถœ๋ ฅ: Hello, my name is Alice and I am 25 years old.

 

2. ํ‘œํ˜„์‹์„ ๋ฌธ์ž์—ด์— ์‚ฝ์ž…

์ค‘๊ด„ํ˜ธ {} ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ๋ณต์žกํ•œ ํ‘œํ˜„์‹์„ ๋„ฃ์„ ์ˆ˜ ์žˆ๋‹ค.

val price = 9.99
val quantity = 3

// ํ‘œํ˜„์‹ ์‚ฌ์šฉ
val total = "The total price is ${price * quantity}."

println(total)  // ์ถœ๋ ฅ: The total price is 29.97.

 

๋ฐ˜์‘ํ˜•