xxxxxxxxxx
fun main() {
println("Hello, world!!!")
x()
}
fun x(){
println("HELLO WORLD")
}
xxxxxxxxxx
// Declare a function in Kotlin
fun happyBirthday(name: String, age: Int): String {
return "Happy ${age}th birthday, $name!"
}
// Call function
val greeting = happyBirthday("Anne", 32)
xxxxxxxxxx
fun callMe() {
println("Printing from callMe() function.")
println("This is cool (still printing from inside).")
}
fun main(args: Array<String>) {
callMe()
println("Printing outside from callMe() function.")
}
xxxxxxxxxx
// Use 'fun' keyword to declare function
// 'num' is the parameter and is of type Int
// The ':Int' indicates the return type
fun square(num: Int):Int {
return num * num
}
xxxxxxxxxx
fun main(args: Array<String>) {
var number = 5.5
print("Result = ${Math.sqrt(number)}")
}
xxxxxxxxxx
fun myFunction(param1: Int, param2: String): String {
return "$param2 $param1"
}