Online Kotlin Compiler
Write, compile, and run Kotlin code in your browser. Great for learning, practice, and quick experiments.
Kotlin Code Editor
Output
Standard Output (stdout)
Standard Error (stderr)
Execution Info
Exit Code:
Status:
How to Use
- Write Kotlin code in the left editor (include
fun main()). - Click “Run Code” to compile and execute online.
- The right panel shows output and errors.
- The green area is standard output (e.g.,
println). - The red area is compile/runtime errors and warnings.
- Execution info includes exit code and status.
- Shortcut:
Ctrl+Enter(orCmd+Enteron Mac).
Kotlin Basics
Hello World:
fun main() {
println("Hello, Kotlin!")
}
println("Hello, Kotlin!")
}
Common Types:
Int/Long/Double/BooleanStringand string templates"Hello ${name}"- Collections:
List/MutableList/Set/Map
Control Flow
Conditionals and Loops:
val n = 5
if (n % 2 == 0) println("even") else println("odd")
for (i in 0 until 3) println(i)
if (n % 2 == 0) println("even") else println("odd")
for (i in 0 until 3) println(i)
Functions and Collections
Example:
fun add(a: Int, b: Int) = a + b
val nums = listOf(3,7,1,9,4)
println(add(2,3))
println(nums.max())
val nums = listOf(3,7,1,9,4)
println(add(2,3))
println(nums.max())
Sample Programs (run them above)
1. Factorial (recursion)
fun factorial(n: Int): Int = if (n <= 1) 1 else n * factorial(n - 1)
fun main() {
println("5! = $${factorial(5)}")
}
fun main() {
println("5! = $${factorial(5)}")
}
2. List maximum
fun main() {
val nums = listOf(3, 7, 1, 9, 4)
println("Maximum: $${nums.max()}")
}
val nums = listOf(3, 7, 1, 9, 4)
println("Maximum: $${nums.max()}")
}