Java 程式查詢圓的周長


圓的周長等於其半徑和 PI 值的乘積的兩倍。因此,為了計算圓的周長

  • 從使用者處獲取圓的半徑。
  • 計算乘積
  • 列印最終結果。

示例:求圓的周長

import java.util.Scanner;
public class CircumfrenceOfCircle {
   public static void main(String args[]){
      int radius;
      double circumference;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the radius of the circle ::");
      radius = sc.nextInt();
      circumference = Math.PI*2*radius;
      System.out.println("Circumference of the circle is ::"+circumference);
   }
}

輸出

Enter the radius of the circle::
55
The circumference of the circle is::345.57519189487726

更新於: 2024-06-24

7K+ 瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

立即開始
廣告
© . All rights reserved.