Introduction to Kotlin
Create a birthday message in Kotlin
Important: A variable declared using the val keyword can only be set once. You cannot change its value later in the program. You can declare a changeable variable with the var keyword, which you will do in a later codelab.
fun main() {
val age = 5 * 365
val name = "John"
println("Happy Birthday, ${name}!")
// Let's print a cake!
println(" ,,,,, ")
println(" ||||| ")
println(" =========")
println("@@@@@@@@@@@")
println("{~@~@~@~@~}")
println("@@@@@@@@@@@")
// This prints an empty line.
println("")
println("You are already ${age} days old, ${name}!")
println("${age} days old is the very best age to celebrate!")
}
fun main() {
printBorder()
println("Happy Birthday, John!")
printBorder()
}
fun printBorder() {
repeat(21) {
print("=")
}
println()
}
Passing arguments to the function to make it more flexible.
fun main() {
val border = "`-._,-'"
val timesToRepeat = 4
printBorder(border, timesToRepeat)
println(" Happy Birthday, John!")
printBorder(border, timesToRepeat)
}
fun printBorder(border: String, timesToRepeat: Int) {
repeat(timesToRepeat) {
print(border)
}
println()
}
fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}
fun printCakeCandles(age: Int) {
print(" ")
repeat(age) {
print(",")
}
println()
print(" ")
repeat(age) {
print("|")
}
println()
}
fun printCakeTop(age: Int) {
repeat(age + 2) {
print("=")
}
println()
}
fun printCakeBottom(age: Int, layers: Int) {
repeat(layers) {
repeat(age + 2) {
print("@")
}
println()
}
}
Create your first Android app
Build a basic layout
Qualities of a great app
- Effective
- Efficient
- Beautiful
- Accessible