package test;
import java.util.Scanner;
/**
* 这是一个使用圆类去计算圆的面积,体积和周长的程序
*/
public class Cricle {
public static void main(String[] args) {
System.out.println("请输入圆的半径: ");
Scanner scanner = new Scanner(System.in);
double radio = scanner.nextDouble();
Cri yuan = new Cri();
yuan.radio = radio;
double area = yuan.getArea();
double volume = yuan.getVolume();
double perimeter = yuan.getPerimeter();
System.out.printf("\n"+"圆的面积为:"+"%.4f",area);
System.out.printf("\n"+"圆的体积为:"+"%.4f",volume);
System.out.printf("\n"+"圆的周长为:"+"%.4f",perimeter);
}
public static class Cri{
double radio;
double getArea() {
//求圆面的面积
return Math.PI *radio*radio;
}
double getVolume() {
//求圆球的体积
return (4.0/3)*Math.PI*radio*radio*radio;
}
double getPerimeter() {
//求圆面的周长
return 2*Math.PI*radio;
}
}
}
[点击并拖拽以移动]
求圆计算,圆类
最新推荐文章于 2024-11-13 20:43:20 发布