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 printCircumferenceAndArea(radius: Double): Unit { | |
fun calCircumference(radius:Double)= (2 * Math.PI) * radius | |
val circumference = "%.2f".format(calCircumference()) | |
fun calArea(radius:Double)= (Math.PI) * Math.pow(radius, 2.0) | |
val area = "%.2f".format(calArea()) | |
// ... | |
} |
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
class Student { | |
var kotlinScore = 0.0 | |
infix fun addKotlinScore(score: Double): Unit { | |
this.kotlinScore = kotlinScore + score | |
} | |
} |
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 student = Student() | |
student addKotlinScore 95.00 | |
print(student.kotlinScore) // will print "95.0" |
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
"Chike" should startWith("ch") | |
myList should contain(myElement) | |
"Chike" should haveLength(5) | |
myMap should haveKey(myKey) |
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
public infix fun <A, B> A.to(that: B): Pair<A, B> = Pair(this, that) |
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 nigeriaCallingCodePair = 234 to "Nigeria" | |
val nigeriaCallingCodePair2 = Pair(234, "Nigeria") // Same as above |
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 nigeriaCallingCodePair3 = 234.to("Nigeria") // same as using 234 to "Nigeria" |
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 callingCodesMap: Map<Int, String> = mapOf(234 to "Nigeria", 1 to "USA", 233 to "Ghana") |
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 callingCodesPairMap: Map<Int, String> = mapOf(Pair(234, "Nigeria"), Pair(1, "USA"), Pair(233, "Ghana")) |
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
map( | |
1 to "one", | |
2 to "two", | |
3 to "three" | |
) |