This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printName(firstName: String, middleName: String = "N/A", lastName: String) { | |
println("first name: $firstName - middle name: $middleName - last name: $lastName") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printName("Chike", "Mgbemena") // won't compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printName("Chike", lastName = "Mgbemena") // will now compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JvmOverloads | |
fun calCircumference(radius: Double, pi: Double = Math.PI): Double = (2 * pi) * radius |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JvmOverloads | |
fun calCircumference(radius: Double, pi: Double = Math.PI): Double = (2 * pi) * radius |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Java | |
double calCircumference(double radius, double pi); | |
double calCircumference(double radius); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printInts(vararg ints: Int): Unit { | |
for (n in ints) { | |
print("$n\t") | |
} | |
} | |
printInts(1, 2, 3, 4, 5, 6) // will print 1 2 3 4 5 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printNumbers(myDouble: Double, myFloat: Float, vararg ints: Int) { | |
println(myDouble) | |
println(myFloat) | |
for (n in ints) { | |
print("$n\t") | |
} | |
} | |
printNumbers(1.34, 4.4F, 2, 3, 4, 5, 6) // will compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun printNumbers(myDouble: Double, vararg ints: Int, myFloat: Float) { | |
println(myDouble) | |
println(myFloat) | |
for (n in ints) { | |
print("$n\t") | |
} | |
} | |
printNumbers(1.34, 2, 3, 4, 5, 6, myFloat = 4.4F) // will compile | |
printNumbers(1.34, ints = 2, 3, 4, 5, 6, myFloat = 4.4F) // will not compile | |
printNumbers(myDouble = 1.34, ints = 2, 3, 4, 5, 6, myFloat = 4.4F) // will also not compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val intsArray: IntArray = intArrayOf(1, 3, 4, 5) | |
printNumbers(1.34, intsArray, myFloat = 4.4F) // won't compile |