zoukankan      html  css  js  c++  java
  • 求等边三角形外接圆面积,并保留n位小数

    public class Demo03 {

    public static void main(String[] args) { //客户端

    System.out.println(round2(getArea(13)));

    System.out.println(round(3.1415926,3));
    System.out.println(round(3.7485926f,4));
    }
    //求正三角形外接圆面积
    public static double getArea(int m){
    //已知正三角形外接圆面积公式:PI*m*m/3
    double s=Math.PI*m*m/(3*1.0);
    return s;
    }

    //对一个double类型进行四舍五入保留两位小数的操作
    public static double round2(double d){
    return (Math.round(d*100))/100.0; //系统提供的round方法
    }

    public static double round(double d,int n){
    //"1"+n0
    String str="1";
    while(n--!=0){
    str+="0";
    }
    int x=Integer.parseInt(str);
    return (Math.round(d*x))/(x*1.0);
    }
    public static double round(float d,int n){
    String str="1";
    while(n--!=0){
    str+="0";
    }
    int x=Integer.parseInt(str);
    return (Math.round(d*x))/(x*1.0);
    }
    }

  • 相关阅读:
    封装
    魔术方法类与有关面向对象的关键字
    JS基础
    轮播效果
    进度条效果
    2018年6月
    2018年5月
    Monte Carlo tree search 学习
    2018年4月
    pachi 学习
  • 原文地址:https://www.cnblogs.com/zhang12354/p/7975807.html
Copyright © 2011-2022 走看看