Π在java中可以用Math.PI来代替,剩下的就很简单了package com.homework.java;import java.util.Scanner;public class Work3 {public static void main(String[] args) {Scanner sc=new Scanner(System.in);System.out.println("请输入圆的半径:");double R=sc.nextDouble();System.out.println("圆的周长约为:");System.out.printf("%.2f\n",CircleLength(R));System.out.println("圆的面积约为:");System.out.printf("%.2f",CircleSquare(R));sc.close();}public static double CircleSquare(double r){double S=Math.PI*Math.pow(r,2);return S;}public static double CircleLength(double r){double L=Math.PI*2*r;return L;}}
如果觉得《圆形的周长 面积怎么计算?(方法练习)》对你有帮助,请点赞、收藏,并留下你的观点哦!