๋ชฉ์ฐจ
๋ฉ์์ง ์ธ์
fun main() {
println("Use the val keyword when the value doesn't change.")
println("Use the var keyword when the value can change.")
println("When you define a function, you define the parameters that can be passed to it.")
println("When you call a function, you pass arguments for the parameters.")
}
์ปดํ์ผ ์ค๋ฅ ์์
fun main() {
println("New chat message from a friend'}
}
fun main() {
println("New chat message from a friend")
}
4. ๋ฌธ์์ด ํ ํ๋ฆฟ
val์ ์ฝ๊ธฐ์ ์ฉ ๋ณ์์ผ ๋!
5. ๋ฌธ์์ด ์ฐ๊ฒฐ
6. ๋ฉ์ธ์ง ์์
fun main() {
val baseSalary = 5000
val bonusAmount = 1000
val totalSalary = "$baseSalary + $bonusAmount"
println("Congratulations for your bonus! You will receive a total of $totalSalary(additional bonus).")
}
<์์>
totalSalary = "5000 + 1000"
7. ๊ธฐ๋ณธ์ ์ธ ์ํ ์ฐ์ฐ ๊ตฌํ
1๋จ๊ณ
(์๋ฃจ์ ์ฝ๋)
fun main() {
val firstNumber = 10
val secondNumber = 5
val result = firstNumber + secondNumber
println("$firstNumber + $secondNumber = $result")
}
2๋จ๊ณ **
(์๋ฃจ์ ์ฝ๋)
fun main() {
val firstNumber = 10
val secondNumber = 5
val thirdNumber = 8
val result = add(firstNumber, secondNumber)
val anotherResult = add(firstNumber, thirdNumber)
println("$firstNumber + $secondNumber = $result")
println("$firstNumber + $thirdNumber = $anotherResult")
}
// Define add() function below this line
fun add(firstNumber: Int, secondNumber: Int): Int {
return firstNumber + secondNumber
}
return ํ ๋ ๋ฐ๋ก ๋ณ์ ์๋ง๋ค์ด๋ ๋๋ค!
??
$๋ณ์์์ ์ธ ๋๋ ์์ธ ๋ ์ฐจ์ด ๊ตฌ๋ถ
์ถ๋ ฅ์ ์ฌ์ฉํ ๋ ๋ฌธ์์ด ๋ด์์ ๋ณ์๋ฅผ ์ฌ์ฉํ ๋ $๋ฅผ ๋ถ์ด๋ ๋ฏํ๋ค.
๋ฌธ์์ด ๋ฆฌํฐ๋ด์ด๋ผ๋ฉด ๋จ์ด ์ฃผ์์ ""๊ฐ ์จ๋ค. ์๋ค๋ฉด ๋ณ์์ด๋ฆ์ด๋ค.
$count -> ๋ฌธ์์ด ํ ํ๋ฆฟ
ํ ํ๋ฆฟ ํํ์์ ๊ฐ์ ํ๊ฐํ ํ ๋ฌธ์์ด์ ๋์ฒดํ๋ ํํ์์ด๋ค. ์ด ๊ฒฝ์ฐ์ ํ ํ๋ฆฟ ํํ์ $count๋ 2๋ก ํ๊ฐ๋๊ณ
2๋ ํํ์์ ์๋ ๋ฌธ์์ด์ ๋์ฒดํ๋ค.
fun main() {
val count: Int = 2
println("You have $count unread messages.")
}
3๋จ๊ณ
??
ํจ์ ๋ฐํํ์ ํญ์ ์ ์ด์ค์ผํ๋ ๊ฒ?
-> ์์
-> ์๋ ๊ฒฝ์ฐ๋ Unit๋๋ ์๋ต๊ฐ๋ฅ
8. ๊ธฐ๋ณธ ๋งค๊ฐ ๋ณ์
1๋จ๊ณ
fun main() {
val operatingSystem = "Chrome OS"
val emailId = "sample@gmail.com"
println(displayAlertMessage(operatingSystem, emailId))
}
// Define your displayAlertMessage() below this line.
fun displayAlertMessage(nameOfSystem:String, emailId: String): String {
var newTried = "There's a new sign-in request on $nameOfSystem for your Google Account $emailId."
return newTried
}
2๋จ๊ณ
9. ๋ง๋ณด๊ณ
์นด๋ฉํ๊ธฐ๋ฒ์ ๋ฐ๋ผ์ผํ๋ค.
์ด๋ฆ์ ์ฌ๋ฌ ๋จ์ด๊ฐ ํฌํจ๋๋ฉด ์ฒซ ๋ฒ์งธ ๋จ์ด์ ์ฒซ ๊ธ์๋ ์๋ฌธ์๋ก ์ฐ๊ณ
๋ค์ ๋จ์ด์ ์ฒซ ๊ธ์๋ ๋๋ฌธ์๋ก ์ฐ๋ฉฐ ๋จ์ด ์ฌ์ด์ ๊ณต๋ฐฑ์ ์ญ์ ํ๋ค.
??
๋ญ๋ ์ฒ์์ ๋๋ฌธ์๋ก ์์ํด์ผํ๋๋ฐ ๊ทธ๊ฒ ๋ญ์๋๋ผ?
10. ๋ ์ซ์ ๋น๊ต
(์๋ฃจ์ ์ฝ๋)
//๋ ์ซ์ ๋น๊ต
fum main() {
println("Have I spent more time using my phone today: ${compareTime(300, 250)}")
println("Have I spent more time using my phone today: ${compareTime(300, 300)}")
println("Have I spent more time using my phone today: ${compareTime(200, 220)}")
}
fun compareTime(timeSpentToday: Int, timeSpentYesterday: Int): Boolean {
return timeSpentToday > timeSpentYesterday
}
์๋ฃจ์ ์ฝ๋๋ ํ๋ฉด ์ค๋ฅ๊ฐ ๋ฌ๋ค............????????????
11. ํจ์๋ก ์ค๋ณต ์ฝ๋ ์ด์ฉ
'2023 ์๋๋ก์ด๋ > ์๋๋ก์ด๋ ์คํฐ๋' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฒซ Android ์ฑ ๋ง๋ค๊ธฐ (0) | 2022.11.15 |
---|---|
์ฒซ ๋ฒ์งธ Android ์ฑ ๋ง๋ค๊ธฐ 5 (0) | 2022.11.15 |
์๋๋ก์ด๋ ์คํฐ๋ 1์ผ์ฐจ ๊ณผ์ unit1 (0) | 2022.11.15 |
Kotlin์์ ํจ์ ๋ง๋ค๊ธฐ ๋ฐ ์ฌ์ฉํ๊ธฐ (0) | 2022.11.14 |
4. Kotlin์์ ๋ณ์ ๋ง๋ค๊ธฐ ๋ฐ ์ฌ์ฉํ๊ธฐ (0) | 2022.11.14 |