圆的面积可以通过公式 **A = 3.14 * r * r** 来计算。其中 **r** 是圆的半径。

要在 Java 中计算圆的面积,我们必须声明类 **Area**。创建 Scanner 类的对象 **sc**,并使用 **nextDouble()** 方法从用户那里读取圆的半径到变量 **r** 中。将其计算为 **a = 3.14 * r * r**。然后使用 `System.out.println()` 显示结果。
步骤 1:声明带有 **public** 修饰符的类 **Area**。
步骤 2:打开 main() 以启动程序,Java 程序执行从 main() 开始
步骤 3:声明变量 a、r 为 double 类型,并设置 **pi=3.14**。
步骤 4:从用户那里读取圆的半径到变量 **r** 中。
步骤 5:计算面积为 **a=pi*r*r**。
步骤 6:显示结果。
import java.util.Scanner;
public class Area{
public static void main(String[] args) {
double pi = 3.14, a,r;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius of the circle:");
r = sc.nextDouble();
a= pi * r * r;
System.out.println("The Area of the circle is :"+a);
}
}
Enter the radius of the circle:15 The Area of the circle is :706.5