Loading…

Online Kotlin Compiler and Playground

Browser-based compiler and playground for Kotlin, Progsity IDE.

About Kotlin

Kotlin is the language most Android apps are written in today, and it runs anywhere Java does. It keeps Java's libraries and drops much of the ceremony: no semicolons, type inference, null safety checked by the compiler, and collection functions that read like the problem statement.

This playground compiles your file with the real Kotlin compiler and runs it on a Java 17 virtual machine inside a sandbox. Write a top-level fun main(), leave out the package line, and use the standard library freely. The first run takes a few seconds because the compiler itself starts on the JVM.

It is the same toolchain the Progsity judge uses, so a solution that passes here behaves the same way in a contest or an exam that allows Kotlin.

How to use

  1. Write a top-level fun main() in the editor. Do not add a package line: the program is one file.
  2. If the program reads input, type it in the stdin panel and read it with readln() or readlnOrNull().
  3. Press Run. Compiler errors show the line and column; fix them and run again.

FAQ

Which Kotlin version runs here?›

Kotlin 2.4, compiled by JetBrains' own compiler and run on OpenJDK 17.

Why does the first run take a few seconds?›

The Kotlin compiler is a JVM program and has to start before it reads your file. The time is spent compiling; your program's own run time is reported separately.

Can I use Java classes?›

Yes. Everything in the Java 17 standard library is available: java.util, java.math.BigInteger, java.io and the rest. Third-party libraries are not.

How do I read input quickly?›

readln() is fine for small input. For a hundred thousand numbers, wrap System.`in` in a BufferedReader and split each line yourself.

Can I save my Kotlin code?›

Yes, after you sign in. A saved snippet has its own link you can share.

Code examples

Tap “Try this” to load sample code into the editor above.

  • Sort and filter a list

    fun main() {
        val nums = listOf(3, 1, 4, 1, 5, 9)
        println(nums.sorted())
        println(nums.filter { it % 2 == 1 }.sum())
    }
  • when as an expression

    fun grade(score: Int): String = when {
        score >= 80 -> "A+"
        score >= 60 -> "A"
        else -> "Try again"
    }
    
    fun main() {
        for (score in listOf(85, 64, 40)) {
            println("$score -> " + grade(score))
        }
    }
  • Read two numbers

    fun main() {
        val (a, b) = readln().split(" ").map { it.toLong() }
        println(a + b)
    }
  • Data class and copy

    data class Point(val x: Int, val y: Int)
    
    fun main() {
        val p = Point(2, 3)
        val q = p.copy(y = 10)
        println(p)
        println(q)
    }