Found 417 Articles for Kotlin

Kotlin Program to Find the Area of a Circle

AmitDiwan
Updated on 13-Oct-2022 13:02:26

797 Views

In this article, we will understand how find the area of a circle. Area of a circle is calculated by using the formula − (pie*radius*radius)/7 Below is a demonstration of the same Suppose our input is Radius of the circle: 5 The desired output would be − The Area of Circle is: 78.57142857142857 Algorithm Step 1 − START Step 2 − Declare two variables radius and myResult Step 3 − Read the value of the radius from the user Step 4 − Calculate the area of the circle by using the formula (22*radius*radius)/7 and store the ... Read More

Kotlin Program to Find the Perimeter of a Rectangle

AmitDiwan
Updated on 13-Oct-2022 13:00:11

315 Views

In this article, we will understand how to find the perimeter of a rectangle. The Perimeter of a rectangle is calculated using the following formulae 2*(length + width) Below is a demonstration of the same − Suppose our input is The length of the sides of a rectangle are: 5, 8, 5, 8 The desired output would be Perimeter : 26 Algorithm Step 1 − START Step 2 − Declare three integer variables length, width and myResult. Step 3 − Define the values. Step 4 − Calculate the perimeter using the formula 2 * (length + ... Read More

Kotlin Program to Calculate Compound Interest

AmitDiwan
Updated on 13-Oct-2022 12:57:52

306 Views

In this article, we will understand how to calculate the Compound interest. The percentage interest charged on principal and accrued interest is Compound Interest. Rates are higher compared to Simple Interest. Compound Interest is calculated using the formula principle * (Math.pow((1 + rate / 100), time)) – principle Below is a demonstration of the same Suppose our input is Principle number: 100000 Interest rate: 5 Time period in years: 3 The desired output would be − The Compound Interest is: 15762.50000000001 Algorithm Step 1 − START Step 2 − Declare four integer values principalAmount, interestRate, timePeriod, ... Read More

Kotlin Program to Calculate Simple Interest

AmitDiwan
Updated on 13-Oct-2022 12:53:38

229 Views

In this article, we will understand how to calculate the Simple Interest in Kotlin. It is the percentage interest on total principal amount. Returns are less compared to Compound Interest. Simple Interest is calculated using the formula (principle*rate*time)/100 Below is a demonstration of the same Suppose our input is Principle number: 100000 Interest rate: 5 Time period in years: 2 The desired output would be Simple Interest: 1000 Algorithm Step 1 − START Step 2 − Declare four integer values principalAmount, interestRate, timePeriod, simpleInterest Step 3 − Define the values for principalAmount, interestRate, timePeriod, simpleInterest Step ... Read More

Kotlin Program to Find Factorial of a number

AmitDiwan
Updated on 13-Oct-2022 12:51:24

1K+ Views

In this article, we will understand how to find the factorial of a number. Factorial of a number is the product of itself with each of its lower numbers. Below is a demonstration of the same − Suppose our input is Enter the number : 5 The desired output would be − The factorial of 5 is 120 Algorithm Step 1 − Start Step 2 − Declare three integers: input, myResult and i Step 3 − Hardcode the integer Step 4 − Run a for-loop, multiply the number with its lower number and run the loop till ... Read More

Kotlin Program to Check Armstrong Number between Two Integers

AmitDiwan
Updated on 13-Oct-2022 12:49:28

622 Views

In this article, we will understand how to display the Armstrong numbers between the given two numbers in Kotlin. An Armstrong number is a number that is equal to the sum of the cubes of its own digits. For example, 153 is 153 = (1)3 + (5)3 + (3)3 Below is a demonstration of the same Suppose our input is 1 & 500 The desired output would be The Armstrong numbers between 1 and 500 are 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407 Algorithm Step 1 − Start Step 2 − ... Read More

Kotlin Program to Display Alphabets (A to Z) using loop

AmitDiwan
Updated on 13-Oct-2022 12:47:18

687 Views

In this article, we will understand how to print alphabets from A to Z or a to z in Kotlin. This is accomplished using a simple for-loop. Below is a demonstration of the same Suppose our input is A to Z The desired output would be A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Algorithm Step 1 − Start Step 2 − Declare a character variable: input Step 3 − Run a while loop with condition input greater that ... Read More

Kotlin Program to Display All Prime Numbers from 1 to N

AmitDiwan
Updated on 13-Oct-2022 12:44:06

2K+ Views

In this article, we will understand how to display all the prime numbers from 1 to N in Kotlin. All possible positive numbers from 1 to infinity are called natural numbers. Prime numbers are special numbers who have only two factors 1 and itself and cannot be divided by any other number. Below is a demonstration of the same Suppose our input is − Value of n :10 The desired output would be − 2 3 5 7 Algorithm Step 1 − Start Step 2 − Declare two integers: low and high Step 3 − Define the ... Read More

Kotlin Program to Find LCM of two Numbers

AmitDiwan
Updated on 13-Oct-2022 12:42:32

492 Views

In this article, we will understand how to calculate the LCM of two numbers in Kotlin. Lowest Common Multiple (LCM) of two numbers is the smallest positive integer that is evenly divisible by both the numbers. Below is a demonstration of the same Suppose our input is 24 and 18 The desired output would be The LCM of the two numbers is 72 Algorithm Step 1 − Start Step 2 − Declare three integers: input1, input2 and myResult Step 3 − Define the values Step 4 − Using a while loop from 1 to the bigger number ... Read More

Kotlin Program to Find GCD of two Numbers

AmitDiwan
Updated on 13-Oct-2022 12:39:09

587 Views

In this article, we will understand how to find the GCD of two numbers in Kotlin. Greatest Common Divisor (GCD) of two numbers is the largest number that divides both. Below is a demonstration of the same Suppose our input is Value 1 : 18 Value 2 : 24 The desired output would be GCD of the two numbers: 6 Algorithm Step 1 − Start Step 2 − Declare three integers: input1, input2 and myResult Step 3 − Define the integer Step 4 − Check that the number divides both (input1 and input2) numbers completely or not. ... Read More

Advertisements