Kotlin程序查找圆的面积
在本文中,我们将了解如何查找圆的面积。圆的面积是使用以下公式计算的:
(pie*radius*radius)/7
下面是相同的演示
假设我们的输入是
Radius of the circle: 5
期望的输出将是:
The Area of Circle is: 78.57142857142857
算法
步骤 1 − 开始
步骤 2 − 声明两个变量radius和myResult
步骤 3 − 从用户处读取radius的值
步骤 4 − 使用公式(22*radius*radius)/7计算圆的面积,并将结果存储为area
步骤 5 − 显示area的值
步骤 6 − 停止
示例 1
在此示例中,我们将使用上述公式查找圆的面积。首先,声明并设置radius
val radius = 5
现在,计算圆的面积并将结果保存在一个新的变量myResult中
val myResult = (22 * (radius.toDouble().pow(2)))/7
现在让我们看看获取圆的面积的示例:
import java.util.* import kotlin.math.pow fun main() { val radius = 5 println("The radius of the circle is defined as $radius") val myResult = (22 * (radius.toDouble().pow(2)))/7 println("Area of circle is: $myResult") }
输出
The radius of the circle is defined as 5 Area of circle is: 78.57142857142857
示例 2
在此示例中,我们将查找圆的面积:
import java.util.* import kotlin.math.pow fun main() { val radius = 5 println("The radius of the circle is defined as $radius") getArea(radius) } fun getArea(radius: Int) { val myResult = (22 * (radius.toDouble().pow(2)))/7 println("Area of circle is: $myResult") }
输出
The radius of the circle is defined as 5 Area of circle is: 78.57142857142857
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP