๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
2023 ์•ˆ๋“œ๋กœ์ด๋“œ/์•ˆ๋“œ๋กœ์ด๋“œ ์Šคํ„ฐ๋””

์—ฐ์Šต๋ฌธ์ œ

by hyeonha 2022. 11. 15.

๋ชฉ์ฐจ

    ๋ฉ”์‹œ์ง€ ์ธ์‡„

    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. ํ•จ์ˆ˜๋กœ ์ค‘๋ณต ์ฝ”๋“œ ์ด์šฉ

     

    728x90