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)

 

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 (or Cmd+Enter on Mac).

Kotlin Basics

Hello World:

fun main() {
  println("Hello, Kotlin!")
}

Common Types:

  • Int / Long / Double / Boolean
  • String and 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)

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())

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)}")
}

2. List maximum

fun main() {
  val nums = listOf(3, 7, 1, 9, 4)
  println("Maximum: $${nums.max()}")
}