Skip to content

Instantly share code, notes, and snippets.

View sajjadyousefnia's full-sized avatar
🤒
Out sick

Sajjad Yousefnia sajjadyousefnia

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