CMAndroidBook
  • CMoney Android Book
  • 新人訓練
    • 工具篇
      • IDE
      • Firebase
      • Flurry
      • Postman
    • Coding Style
    • 架構
  • 基礎課程-預習
    • Android Studio
    • Kotlin練習
      • Google Code Labs
        • 1: Get started
        • 2: Kotlin basics
        • 3: Functions
        • 4: Object-oriented programming
        • 5.1: Extensions
      • 程式練習題
      • 參考
  • 建立第一個App
    • 目標
    • 建立專案
    • 專案結構
    • 手機開發者權限
    • IDE Git常用操作
      • 初始化Git
      • Commit
      • 新增、刪除、切換Branch
      • 合併Branch
      • 解衝突
  • Coroutine
    • Kotlin-Coroutine
      • 並發與並行
      • Overview
      • 概念
      • Scope和Context
      • Suspend修飾符
    • 習題
    • 參考資源
Powered by GitBook
On this page
  • Question 1
  • Question 2

Was this helpful?

  1. 基礎課程-預習
  2. Kotlin練習
  3. Google Code Labs

3: Functions

Question 1

The contains(element: String) function returns true if the string element is contained in the string it's called on. What will be the output of the following code?

val decorations = listOf ("rock", "pagoda", "plastic plant", "alligator", "flowerpot")
println(decorations.filter {it.contains('p')})

Question 2

In the following function definition, which one of the parameters is required?

fun shouldChangeWater(
    day: String, 
    temperature: Int = 22,
    dirty: Int = 20,
    numDecorations: Int = 0
): Boolean {...}

Question 3

You can pass a regular named function (not the result of calling it) to another function. How would you pass increaseDirty( start: Int ) = start + 1 to updateDirty(dirty: Int, operation: (Int) -> Int)?

Previous2: Kotlin basicsNext4: Object-oriented programming

Last updated 4 years ago

Was this helpful?