Kotlin Program to Calculate the Sum of Natural Numbers In this program, you’ll learn to calculate the sum of natural numbers using for loop and while loop in Kotlin. You’ll also see how ranges can be helpful for solving the problem. The positive numbers 1, 2, 3… are known as natural numbers and its sum …
Kotlin Program to Check Whether a Character is Alphabet or Not In this program, you’ll learn to check whether a given character is an alphabet or not. This is done using an if else statement or when expression in Kotlin. Example 1: Kotlin Program to Check Alphabet using if else fun main(args: Array<String>) { val …
Kotlin Program to Check Leap Year In this program, you’ll learn to check if the given year is a leap year or not in Kotlin. This is checked using a if else statement and a when statement. A leap year is exactly divisible by 4 except for century years (years ending with 00). The century …
Kotlin Program to Find all Roots of a Quadratic Equation In this program, you’ll learn to find all roots of a quadratic equation (depending upon the determinant) and print them using format() in Kotlin. The standard form of a quadratic equation is: ax2 + bx + c = 0, where a, b and c are …
Kotlin Program to Check Whether an Alphabet is Vowel or Consonant In this program, you’ll learn to check whether an alphabet is a vowel or a consotant using if..else and when statement in Kotlin. Example 1: Check whether an alphabet is vowel or consonant using if..else statement fun main(args: Array<String>) { val ch = ‘i’ …
Kotlin Program to Check Whether a Number is Even or Odd In this program, you’ll learn to check if a number entered by an user is even or odd. This will be done using two variants of if…else in Kotlin. Example 1: Check whether a number is even or odd using if…else statement import java.util.* …
Kotlin Program to Swap Two Numbers In this program, you’ll learn two techniques to swap two numbers in Kotlin. The first one uses a temporary variable for swapping, while the second one doesn’t use any temporary variables. Example 1: Swap two numbers using temporary variable fun main(args: Array<String>) { var first = 1.20f var second …
Kotlin Program to Compute Quotient and Remainder In this program, you’ll learn to compute quotient and remainder from the given dividend and divisor in Kotlin. Example: Compute Quotient and Remainder fun main(args: Array<String>) { val dividend = 25 val divisor = 4 val quotient = dividend / divisor val remainder = dividend % divisor println(“Quotient …
Kotlin Program to Find ASCII value of a character In this program, you’ll learn to find and display the ASCII value of a character in Kotlin. This is done using type-casting and normal variable assignment operations. Example: Find ASCII value of a character fun main(args: Array) { val c = ‘a’ val ascii = c.toInt() …
Kotlin Program to Multiply two Floating Point Numbers In this program, you’ll learn to multiply two floating point numbers in Kotlin, store the result and display it on the screen. Example: Multiply Two Floating Point Numbers fun main(args: Array<String>) { val first = 1.5f val second = 2.0f val product = first * second println(“The …