Simple basic Kotlin sample code with explanation:
fun main() {
// Declare and initialize a variable of type String
val name: String = "John Doe"
// Print a greeting message using the variable
println("Hello, $name!")
// Calculate the sum of two integers
val num1 = 10
val num2 = 20
val sum = num1 + num2
println("The sum of $num1 and $num2 is $sum")
// Check if a number is even or odd
val num3 = 15
if (num3 % 2 == 0) {
println("$num3 is an even number.")
} else {
println("$num3 is an odd number.")
}
}
Explanation:
This simple code demonstrates basic programming concepts such as variable declaration, data types, arithmetic operations, conditional statements, and string formatting.