관리 메뉴

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.

 

λ°˜μ‘ν˜•