Kotlin Program to Display Prime Numbers Between Two Intervals In this program, you’ll learn to display prime numbers between two given intervals, low and high. You’ll learn to do this using a while and a for loop in Kotlin. Example: Display Prime Numbers Between two Intervals fun main(args: Array<String>) { var low = 20 val …
Day: May 5, 2021
Kotlin Program to Check Whether a Number is Prime or Not In this article, you’ll learn to check whether a number is prime or not. This is done using a for-in loop in Kotlin. Example 1: Program to Check Prime Number using a for-in loop fun main(args: Array<String>) { val num = 29 var flag …
Kotlin Program to Calculate the Power of a Number In this program, you’ll learn to calculate the power of a number with and without using pow() function. Example 1: Calculate power of a number without using pow() fun main(args: Array<String>) { val base = 3 var exponent = 4 var result: Long = 1 while …
Kotlin Program to Calculate the Power of a Number In this program, you’ll learn to calculate the power of a number with and without using pow() function. Example 1: Calculate power of a number without using pow() fun main(args: Array<String>) { val base = 3 var exponent = 4 var result: Long = 1 while …
Kotlin Program to Display Characters from A to Z using loop In this program, you’ll learn to print English alphabets using while loop in Kotlin. You’ll also learn learn to print only uppercased and lowercased alphabets. Example 1: Display Uppercased A to Z fun main(args: Array<String>) { var c: Char c = ‘A’ while (c …
Kotlin Program to Find GCD of two Numbers In this program, you’ll learn to find GCD of two numbers in Kotlin. This is done by using while loop with the help of if else statement. The HCF or GCD of two integers is the largest integer that can exactly divide both numbers (without a remainder). …
Kotlin Program to Display Fibonacci Series In this program, you’ll learn to display fibonacci series in Kotlin using for and while loops. You’ll learn to display the series upto a specific term or a number. The Fibonacci series is a series where the next term is the sum of pervious two terms. The first two …
Kotlin Program to Generate Multiplication Table In this program, you’ll learn to generate multiplication table of a given number. This is done by using a for and a while loop in Kotlin. You’ll also learn to use ranges to solve the problem. Example 1: Generate Multiplication Table using for loop fun main(args: Array<String>) { val …
Kotlin Program to Find Factorial of a Number In this program, you’ll learn to find the factorial of a number using for and while loop in Kotlin. You’ll also learn to use ranges to solve this problem. The factorial of a positive number n is given by: factorial of n (n!) = 1 * 2 * 3 …
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 …