This Is The Program Code in The Editor
This Is The Program Code in The Editor
fun main() {
println("Hello, world!")
}
Let's see what this program does!
1. In the editor, in the top-right corner, find the white or green
Comments
An inline comment starts with // followed by text, as shown below.
val age = 5
This line means:
val is a special word used by Kotlin, called a keyword, indicating that
what follows is the name of a variable.
age is the name of the variable.
= makes the value of age (on its left) be the same as the value on its
right. In math, a single equal sign is used to assert that the values on
each side are the same. In Kotlin, unlike in math, a single equal sign
is used to assign the value on the right to the named variable on the
left.
A developer would say it like this: This line declares a variable
named age whose assigned value is 5.
To use a variable inside a print statement, you need to surround it with
some symbols that tell the system that what comes next is not text, but a
variable. Instead of printing text, the system needs to print the value of
the variable. You do this by putting your variable inside curly braces
preceded by a dollar sign, like in the example below.
${variable}
Example
1. a variable called name for the name of the birthday person and set
its value to "Rover".
val name = "Rover"
2. Replace the name Rover in the birthday message with the variable,
as shown below.
println("Happy Birthday, ${name}!")
fun printBorder() {
println("=======================")
}
you can make your code more smart by using repeat()
fun main() {
val border = "%"
printBorder(border)
println("Happy Birthday, Jhansi!")
printBorder(border)
}
fun printBorder(border: String) {
repeat(23) {
print(border)
}
println()
}
again modify your code
fun main() {
val border = "`-._,-'"
val timesToRepeat = 4
printBorder(border, timesToRepeat)
println(" Happy Birthday, Jhansi!")
printBorder(border, timesToRepeat)
}
fun printBorder(border: String, timesToRepeat: Int) {
repeat(timesToRepeat) {
print(border)
}
println()
}
observe it
fun main() {
val age = 24
val layers = 5
printCakeCandles(age)
printCakeTop(age)
printCakeBottom(age, layers)
}