Kotlin 函数与递归:从基础到高级应用
1. 带默认参数的函数
在 Kotlin 中,函数可以有默认参数。以下是一个示例:
fun students(names: String="Praniti", standard: String="IX", roll_no: Int=11) {
println("The Name of the students is: $names")
println("The Standard of the students is: $standard")
println("The Roll no of the students is: $roll_no")
}
fun main(args: Array<String>) {
val names_of_students = "Gautam"
val standard_of_students = "VII"
val roll_no_of_students = 23
students()
}
在这个程序中, students 函数有三个参数 names 、 standard 和 roll_no ,并且都有默认值。当调用 students() 时没有传递任何参数,函数将使用默认参数并输出默认值。
2. 调用函数时传递部分参数
当调用函数时,可以只传递部分参数,未传递的
超级会员免费看
订阅专栏 解锁全文
13

被折叠的 条评论
为什么被折叠?



