Kotlin Articles

Page 2 of 21

Kotlin Program to Generate Multiplication Table

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will understand how to print a multiplication table. Multiplication table is created by iterating the required input 10 times using a for loop and multiplying the input value with numbers from 1 to 10 in each iteration. Below is a demonstration of the same − Suppose our input is − Input : 16 The desired output would be − The multiplication table of 16 is : 16 * 1 = 16 16 * 2 = 32 16 * 3 = 48 16 * 4 = 64 16 * 5 = 80 16 * 6 = ...

Read More

Kotlin Program to Round a Number to n Decimal Places

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 2K+ Views

In this article, we will understand how to round a number to n decimal places. Rounding of decimal values are done using the ceil() or floor() functions. Below is a demonstration of the same − Suppose our input is Input : 3.1415 The desired output would be − Output : 3.2 Algorithm Step 1 − START Step 2 − Declare a float value namely myInput. Step 3 − Define the values Step 4 − Use format() to alter the number of decimal places required. Store the result. Step 5 − Display the result Step 6 − Stop ...

Read More

Kotlin Program to calculate Simple Interest and Compound Interest

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will input the Principal Amount, Rate and Time (Years) from the user to find the Simple Interest and Compound Interest − Simple Interest − The percentage interest on total principal amount. Returns are less compared to Compound Interest. Compound Interest − The percentage interest charged on principal and accrued interest. Rates are higher compared to Simple Interest. Below is a demonstration of the same − Suppose our input is − Principal = 25000.0 Annual Rate of Interest = 10.0 Time (years) = 4.0 The desired output would be − Simple Interest: 10000.0 Compound ...

Read More

Kotlin Program to Count the Number of Vowels and Consonants in a Sentence

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will understand how to count the vowels and consonants in Kotlin. Alphabets that include the following are called Vowels − ‘a’ ‘e’ ‘i’ ‘o’ ‘u’ All other alphabets are called Consonants. Suppose our input is − Hello, my name is Charlie The desired output would be − The number of vowels in the statement is: 8 The number of vowels in the Consonants is: 12 Algorithm Step 1 − Start Step 2 − Declare two integers: vowelsCount, consonantsCount and a string input Step 3 − Define the values Step 4 − Run ...

Read More

Kotlin Program to Find all Roots of a Quadratic Equation

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 923 Views

In this article, we will understand how to calculate the roots of a quadratic equation in Kotlin. A quadratic equation is an algebraic expression of the second degree or in other words, it has two results i.e., real number and an imaginary number. Below is a demonstration of the same Suppose our input is − a = 1, b = 2, c = 3 The desired output would be − The roots of the quadratic equation are root1 = -1.00+1.41i root2 = -1.00-1.41i Algorithm Step 1 − Start Step 2 − Declare six values: inputA, inputB, inputC, ...

Read More

Kotlin Program to Find the Largest Among Three Numbers

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will understand how to find the largest of three integers in Kotlin. This is done using a greater than operator (= input2 && input1 >= input3) println("The first value i.e $input1 is the largest number.") else if (input2 >= input1 && input2 >= input3) println("The second value i.e $input2 is the largest number.") else println("The third value i.e $input3 is the largest number.") Let us now see the complete example to find the largest among three numbers in Kotlin − fun main() { ...

Read More

Kotlin Program to Compute Quotient and Remainder

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 745 Views

In this article, we will understand how to compute the quotient and reminder in Kotlin. Quotient and Reminder is calculated using two simple formulae − “Quotient = Dividend / Divisor” “Remainder = Dividend % Divisor” Below is a demonstration of the same Suppose our input is − Dividend value: 50 Divisor: 3 The desired output would be − Quotient: 16 Remainder: 2 Algorithm Step 1 − Start Step 2 − Declare four integers as myDividend , myDivisor, resultQuotient, resultRemainder Step 3 − Define the integers Step 4 − Use the formula to find the quotient and ...

Read More

Kotlin Program to Print the ASCII values

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 1K+ Views

In this article, we will understand how to print ascii values of characters. This is done by assigning the character to an integer value and printing those integer values. Below is a demonstration of the same Suppose our input is − Enter a character: s The desired output would be − Ascii value of s is 115 Algorithm Step 1 − Start Step 2 − Declare a char as input Step 3 − Define the character Step 4 − Assign the character to an integer variable using toInt() function and store it in myResult. Step 5 − ...

Read More

Kotlin Program to Find the Surface Area and Volume of Cuboid

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 332 Views

In this article, we will understand how to compute the surface area and volume the cuboid. The surface area of cuboid is calculated using the formula − 2*( length *width + width* height + height*length) The Volume of the cuboid is calculated using the formula length*width*height Below is a demonstration of the same − Suppose our input is − length= 6; width= 7; height= 8; The desired output would be − Volume Of the Cuboid is : 336.0 Surface area Of the Cuboid is : 292.0 Algorithm Step 1 − START Step 2 − Declare ...

Read More

Kotlin Program to Find the Perimeter of a Rectangle

AmitDiwan
AmitDiwan
Updated on 13-Oct-2022 639 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
Showing 11–20 of 202 articles
« Prev 1 2 3 4 5 21 Next »
Advertisements