Java 程序用于查找圆的周长
javaobject oriented programmingprogramming更新于 2024/4/14 1:16:17
在本文中,我们将了解如何查找圆的周长。圆周就是圆的周长。它是圆周的距离。
圆周率由公式 C = 2𝜋\pi r 给出,其中 \pi𝜋 = 3.14,r 是圆的半径 −

下面是相同的演示 −
输入
假设我们的输入是 −
圆的半径:5
输出
所需的输出将是 −
圆的周长为:31.428571428571427
算法
步骤 1 - 开始 步骤 2 - 声明 2 个双精度值,即 my_radius 和 my_perimeter 步骤 3 - 从用户处读取所需值/定义值 步骤 4 - 使用公式 (2*22*7)/7 计算周长并存储 结果。 步骤 5- 显示结果 步骤 6- 停止
示例 1
import java.util.Scanner;
public class PerimeterOfCircle{
public static void main(String args[]){
double my_radius, my_perimeter;
System.out.println("Required packages have been imported");
Scanner my_scanner = new Scanner(System.in);
System.out.println("A reader object has been defined ");
System.out.print("Enter the radius of the circle : ");
my_radius = my_scanner.nextDouble();
my_perimeter =(22*2*my_radius)/7 ;
System.out.println("The perimeter of Circle is: " +my_perimeter);
}
}
输出
Required packages have been imported A reader object has been defined Enter the radius of the circle : 5 The perimeter of Circle is: 31.428571428571427
示例 2
这里,整数已经被预先定义,并且它的值被访问并显示在控制台上。
public class PerimeterOfCircle{
public static void main(String args[]){
double my_radius, my_perimeter;
my_radius = 5;
System.out.println("The radius of the circle is defined as " +my_radius);
my_perimeter =(22*2*my_radius)/7 ;
System.out.println("The perimeter of Circle is: " +my_perimeter);
}
}
输出
The radius of the circle is defined as 5.0 The perimeter of Circle is: 31.428571428571427
相关文章
有用资源
java 参考教程 - 该教程包含有关 java 的更多信息:https://www.cainiaomax.com/java/

