Kotlin Program to Find Area of Square



In this article, we will understand how to find the Area of a Square. The area of a square is calculated using the formula.

side*side

Below is a demonstration of the same ?

Suppose our input is ?

Length of the side : 4

The desired output would be ?

Area of the square : 16

Algorithm

  • Step 1 ? START.

  • Step 2 ? Declare 2 integer values namely sideValue and myResult.

  • Step 3 ? Define the values.

  • Step 4 ? Calculate the area of the square using the formula side*side and store the result.

  • Step 5 ? Display the result.

  • Step 6 ? Stop.

Example 1

In this example, we will find the Area of Square using its' sides as shown in the above formula. First, declare and initialize a variable for the side.

val sideValue = 4

Then, find the Area of Square ?

val myResult = sideValue * sideValue

Let us now see the complete example to find the Area of Square ?

fun main() { val sideValue = 4 println("The length of side of the square is defined as $sideValue") val myResult = sideValue * sideValue println("The area of square is: $myResult") }

Output

The length of side of the square is defined as 4
The area of square is: 16

Example 2

In this example, we will find the Area of Square.

fun main() { val sideValue = 4 println("The length of side of the square is defined as $sideValue") squareArea(sideValue) } fun squareArea(sideValue: Int) { val myResult = sideValue * sideValue println("The area of square is: $myResult") }

Output

The length of side of the square is defined as 4
The area of square is: 16
Updated on: 2022-10-17T08:36:25+05:30

718 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements