Kotlin Examples
The best way to learn any programming language is by practicing examples on your own.
You are advised to take references of these examples and try them on your own.
All Kotlin programs in this page are tested and should work on almost all Kotlin compilers.
Feel free to use the source code on your system.
Kotlin Program to Print an Integer (Entered by the User) |
Kotlin Program to Add Two Integers |
Kotlin Program to Multiply two Floating Point Numbers |
Kotlin Program to Find ASCII value of a character |
Kotlin Program to Compute Quotient and Remainder |
Kotlin Program to Swap Two Numbers |
Kotlin Program to Check Whether a Number is Even or Odd |
Kotlin Program to Check Whether an Alphabet is Vowel or Consonant |
Kotlin Program to Find the Largest Among Three Numbers |
Kotlin Program to Find all Roots of a Quadratic Equation |
Kotlin Program to Check Leap Year |
Kotlin Program to Check Whether a Number is Positive or Negative |
Kotlin Program to Check Whether a Character is Alphabet or Not |
Kotlin Program to Calculate the Sum of Natural Numbers |
Kotlin Program to Find Factorial of a Number |
Kotlin Program to Generate Multiplication Table |
Kotlin Program to Display Fibonacci Series |
Kotlin Program to Find GCD of two Numbers |
Kotlin Program to Find LCM of two Numbers |
Kotlin Program to Display Characters from A to Z using loop |
Kotlin Program to Count Number of Digits in an Integer |
Kotlin Program to Reverse a Number |
Kotlin Program to Calculate the Power of a Number |
Kotlin Program to Check Whether a Number is Palindrome or Not |
Kotlin Program to Check Whether a Number is Prime or Not |
Kotlin Program to Display Prime Numbers Between Two Intervals |
Kotlin Program to Check Armstrong Number |
Kotlin Program to Display Armstrong Number Between Two Intervals |
Kotlin Program to Display Prime Numbers Between Intervals Using Function |
Kotlin Program to Display Armstrong Numbers Between Intervals Using Function |
Kotlin Program to Display Factors of a Number |
Kotlin Program to Make a Simple Calculator Using switch…case |
Kotlin Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers |
Kotlin Program to Find the Sum of Natural Numbers using Recursion |
Kotlin Program to Find Factorial of a Number Using Recursion |
Kotlin Program to Find G.C.D Using Recursion |
Kotlin Program to Convert Binary Number to Decimal and vice-versa |
Kotlin Program to Convert Octal Number to Decimal and vice-versa |
Kotlin Program to Convert Binary Number to Octal and vice-versa |
Kotlin Program to Reverse a Sentence Using Recursion |
Kotlin Program to calculate the power using recursion |
Kotlin Program to Calculate Average Using Arrays |
Kotlin Program to Find Largest Element in an Array |
Kotlin Program to Calculate Standard Deviation |
Kotlin Program to Add Two Matrix Using Multi-dimensional Arrays |
Kotlin Program to Multiply to Matrix Using Multi-dimensional Arrays |
Kotlin Program to Multiply two Matrices by Passing Matrix to a Function |
Kotlin Program to Find Transpose of a Matrix |
Kotlin Program to Find the Frequency of Character in a String |
Kotlin Program to Count the Number of Vowels and Consonants in a Sentence |
Kotlin Program to Sort Elements in Lexicographical Order (Dictionary Order) |
Kotlin Program to Add Two Complex Numbers by Passing Class to a Function |
Kotlin Program to Calculate Difference Between Two Time Periods |
Kotlin Code To Create Pyramid and Pattern |
Kotlin Program to Remove All Whitespaces from a String |
Kotlin Program to Print an Array |
Kotlin Program to Convert String to Date |
Kotlin Program to Round a Number to n Decimal Places |
Kotlin Program to Concatenate Two Arrays |
Kotlin Program to Convert Character to String and Vice-Versa |
Kotlin Program to Check if An Array Contains a Given Value |
Kotlin Program to Check if a String is Empty or Null |
Kotlin Program to Get Current Date/TIme |
Kotlin Program to Convert Milliseconds to Minutes and Seconds |
Kotlin Program to Add Two Dates |
Kotlin Program to Join Two Lists |
Kotlin Program to Convert List (ArrayList) to Array and Vice-Versa |
Kotlin Program to Get Current Working Directory |
Kotlin Program to Convert Map (HashMap) to List |
Kotlin Program to Convert Array to Set (HashSet) and Vice-Versa |
Kotlin Program to Convert Byte Array to Hexadecimal |
Kotlin Program to Create String from Contents of a File |
Kotlin Program to Append Text to an Existing File |
Kotlin Program to Convert a Stack Trace to a String |
Kotlin Program to Convert File to byte array and Vice-Versa |
Kotlin Program to Convert InputStream to String |
Kotlin Program to Convert OutputStream to String |
Kotlin Program to Lookup enum by String value |
Kotlin Program to Compare Strings |
Kotlin Program to Sort a Map By Values |
Kotlin Program to Sort ArrayList of Custom Objects By Property |
Kotlin Program to Check if a String is Numeric |