昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

用java实现正n边形的问题

public class RegularPolygon {
//    多边形的边数
    private int n;
//    存储边的长度
    private double side;
//    多边形中点的x坐标
    private double x;
//   多边形中点的y坐标
    private double y;

    public RegularPolygon() {
        n=3;
        side=1;
        x=0;
        y=0;
    }

    public RegularPolygon(int n, double side) {
        this.n = n;
        this.side = side;
        x=0;
        y=0;
    }

    public RegularPolygon(int n, double side, double x, double y) {
        this.n = n;
        this.side = side;
        this.x = x;
        this.y = y;
    }

    public int getN() {
        return n;
    }

    public void setN(int n) {
        this.n = n;
    }

    public double getSide() {
        return side;
    }

    public void setSide(double side) {
        this.side = side;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
    public double getPerimeter(){
        return n*side;
    }
    public double getArea(){
        return ((n*Math.pow(side,2))/(4*Math.tan(Math.PI/n)));
    }


 public static void main(String[] args) {
        RegularPolygon regularPolygon1=new RegularPolygon();
        System.out.println("周长为:\t"+regularPolygon1.getPerimeter());
        System.out.println("面积为:\t"+regularPolygon1.getArea());

        RegularPolygon regularPolygon2=new RegularPolygon(6,4);
        System.out.println("周长为:\t"+regularPolygon2.getPerimeter());
        System.out.println("面积为:\t"+regularPolygon2.getArea());


        RegularPolygon regularPolygon3=new RegularPolygon(10,4,5.6,7.8);
        System.out.println("周长为:\t"+regularPolygon3.getPerimeter());
        System.out.println("面积为:\t"+regularPolygon3.getArea());
    }

}





posted on 2024-06-28 12:29  Indian_Mysore  阅读(10)  评论(0)    收藏  举报

导航