English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Kotlin complete example collection

The best way to learn Kotlin is through practice examples. This page contains examples of basic Kotlin concepts. It is recommended that you learn from these examples and then try them yourself.

All programs on this page have been tested and can run on all platforms.


  1. Kotlin program to print an integer (input by the user)

  2. Kotlin program to add two integers

  3. Kotlin program to multiply two floating-point numbers

  4. Kotlin program to find the ASCII value of a character

  5. Kotlin program to calculate quotient and remainder

  6. Kotlin program to swap two numbers

  7. Kotlin program to check if a number is even or odd

  8. Kotlin program to check if a letter is a vowel or consonant

  9. Kotlin program to find the largest number among three numbers

  10. Kotlin program to find all roots of a quadratic equation

  11. Kotlin program to check if a year is a leap year

  12. Kotlin program to check if a number is positive or negative

  13. Kotlin program to check if a character is a letter

  14. Kotlin program to calculate the sum of natural numbers

  15. Kotlin program to find the factorial of a number

  16. Kotlin program to generate a multiplication table

  17. Kotlin program to display the Fibonacci sequence

  18. Kotlin program to find the GCD (Greatest Common Divisor) of two numbers

  19. Kotlin program to find the LCM of two numbers

  20. Kotlin program to display characters from A to Z using a loop

  21. Kotlin program to calculate the number of digits in an integer

  22. Kotlin program to reverse a number

  23. Kotlin program to calculate the power of a number

  24. Kotlin program checks if a number is a palindrome

  25. Kotlin program checks if a number is a prime number

  26. Kotlin programs to display prime numbers between two intervals

  27. Kotlin programs to check Armstrong numbers

  28. Kotlin programs to display Armstrong numbers between two intervals

  29. Kotlin programs to display prime numbers between two intervals using a function

  30. Kotlin programs to display Armstrong numbers between two intervals using a function

  31. Kotlin programs to display the factors of a number

  32. Kotlin programs to create a simple calculator using switch ... case

  33. Kotlin programs to check if a number can be represented as the sum of two prime numbers

  34. Kotlin programs to find the sum of natural numbers using recursion

  35. Kotlin programs to find the factorial of a number using recursion

  36. Kotlin programs to find GCD using recursion

  37. Kotlin programs to convert binary numbers to decimal

  38. Kotlin programs to convert octal numbers to decimal

  39. Kotlin programs to convert binary numbers to octal

  40. Kotlin programs to reverse a sentence using recursion

  41. Kotlin programs to calculate the power using recursion

  42. Kotlin programs to calculate the average using an array

  43. Kotlin programs to find the largest element in an array

  44. Kotlin programs to calculate the standard deviation

  45. Kotlin programs to add two matrices using a multi-dimensional array

  46. Kotlin programs to multiply a matrix with a multi-dimensional array

  47. Kotlin programs to multiply two matrices by passing them to a function

  48. Kotlin programs to find the transpose of a matrix

  49. Kotlin programs to find the frequency of characters in a string

  50. Kotlin programs calculate the number of vowels and consonants in a sentence

  51. Kotlin programs sort elements in alphabetical order (dictionary order)

  52. Kotlin programs add two complex numbers by passing a class to a function

  53. Kotlin programs to calculate the time difference between two time periods

  54. Kotlin code creates pyramids and patterns

  55. Kotlin programs remove all spaces from a string

  56. Kotlin programs print an array

  57. Kotlin programs convert a string to a date

  58. Kotlin programs round a number to decimal places

  59. Kotlin programs concatenate and merge two arrays

  60. Kotlin programs convert a character (char) to a string

  61. Kotlin programs check if an array contains a given value

  62. Kotlin programs check if a string is empty or null

  63. Kotlin programs get the current date/Time

  64. Kotlin programs convert milliseconds to minutes

  65. Kotlin programs add two dates

  66. Kotlin programs merge two lists

  67. Kotlin programs convert ArrayLists to Arrays

  68. Kotlin programs get the current working directory

  69. Kotlin programs convert mappings (HashMap) to lists

  70. Kotlin programs convert arrays to Sets (HashSet)

  71. Kotlin Program Converts Byte Array to Hexadecimal

  72. Kotlin Program Creates String from File Content

  73. Kotlin Program Appends Text to Existing File

  74. Kotlin Program Converts Stack Trace to String

  75. Kotlin Program Converts File to Byte Array and Vice Versa

  76. Kotlin Program Converts InputStream to String

  77. Kotlin Program Converts OutputStream to String

  78. Kotlin Program Finds Enum by String Value

  79. Kotlin Program Compares Strings

  80. Kotlin Program Sorts Map by Value

  81. Kotlin Program Sorts Custom Object ArrayList by Property

  82. Kotlin Program Checks If a String Is a Number