Java
 Computer >> コンピューター >  >> プログラミング >> Java

Javaプログラムで円の面積を見つける


この記事では、円の面積を見つける方法を理解します。円の面積は、式-

を使用して計算されます。
pie*radius*radius.
i.e.
πr2
Where π = 3.14 and r is the radius of the circle.

以下は同じのデモンストレーションです-

入力

入力が-

であると仮定します
Radius of the circle : 5

出力

必要な出力は-

になります
The Area of Circle is: 78.57142857142857

アルゴリズム

Step 1 – START
Step 2 – Declare 2 double variables area and radius
Step 3 – Read the value of the radius from the user
Step 4- Calculate the area of the circle by using the formula (22*radius*radius)/7 and store
the result as area
Step 5- Display the area value
Step 6 – STOP

例1

ここでは、プロンプトに基づいてユーザーが入力を入力しています。この例は、コーディンググラウンドツールでライブで試すことができます Javaプログラムで円の面積を見つける

import java.util.Scanner;
public class AreaOfCircle{
   public static void main(String args[]){
      double area, radius;
      System.out.println("Required packages have been imported");
      Scanner my_scanner= new Scanner(System.in);
      System.out.println("A Scanner object has been defined ");
      System.out.println("Enter the radius of the circle:");
      radius= my_scanner.nextDouble();
      area=(22*radius*radius)/7 ;
      System.out.println("The Area of Circle is: " + area);
   }
}

出力

Required packages have been imported
A Scanner object has been defined
Enter the radius of the circle:
5
The Area of Circle is: 78.57142857142857

例2

ここでは、整数は事前に定義されており、その値にアクセスしてコンソールに表示されます。

public class AreaOfCircle{
   public static void main(String args[]){
      double area, radius;
      radius= 5;
      System.out.printf("The radius of the circle is %.8f ", radius);
      area=(22*radius*radius)/7 ;
      System.out.println("\nThe Area of Circle is: " + area);
   }
}

出力

The radius of the circle is 5.00000000
The Area of Circle is: 78.57142857142857

  1. 正方形の領域を見つけるJavaプログラム

    この記事では、正方形の面積を見つける方法を理解します。正方形の面積は、次の式を使用して計算されます- side*side i.e. s2 以下は同じのデモンストレーションです- 正方形の辺がsの場合、正方形の面積はs 2で与えられます。 − 入力 入力が-であると仮定します Length of the side : 4 出力 必要な出力は-になります Area of the square : 16 アルゴリズム Step 1 - START Step 2 - Declare 2 integer values namely my_side and my_area. S

  2. 長方形の周囲を見つけるJavaプログラム

    この記事では、長方形の周囲を見つける方法を理解します。長方形の周囲長は、長方形のすべての辺の長さを加算して計算されます。 以下は長方形のデモンストレーションです。長方形の周囲は、長方形の2つの長さと2つの幅の全長です- 入力 入力が-であると仮定します The length of the sides of a rectangle are : 5, 8, 5, 8 出力 必要な出力は-になります Perimeter : 26 アルゴリズム Step 1 – START Step 2 – Declare 5 floating point variabl