The perimeter of a circle is the distance around a closed figure, which in this case is a circle. It is also known as the circumference. It is the product of 2, pi, and the circle's radius.
All we need to do to find this value is to create a constant called pi
using the val
keyword. Next, we multiply this with other values.
2 * PI * radius
PI
: This is pi in mathematics. Its value is 3.14
.radius
: This is the radius specified.The value returned is a float, which is the total distance around the circle.
// import the math moduleimport scala.math._object Main extends App {// create a PI valueval PI = Math.PI// create some radiivar rad1 = 3var rad2 = 45var rad3 = 1.5var rad4 = 0.1// get the perimeter of criclesvar per1 = 2 * PI * rad1var per2 = 2 * PI * rad2var per3 = 2 * PI * rad3var per4 = 2 * PI * rad4// print the perimetersprintln("The perimeter of area of radius "+rad1+" is: "+per1)println("The perimeter of area of radius "+rad2+" is: "+per2)println("The perimeter of area of radius "+rad3+" is: "+per3)println("The perimeter of area of radius "+rad4+" is: "+per4)}
Math
module.PI
constant value.