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);
    }
    }

  • 相关阅读:
    java网络请求工具类
    MySql 日期比较大小
    JAVA泛型整理
    循环list从list中移除数据
    MySql UNION字段
    session理解
    IDEA鼠标悬停提示变量值
    JAVA常用的RPC框架
    字符串查找重复字符最多的
    java List分组
  • 原文地址:https://www.cnblogs.com/zhang12354/p/7975807.html
Copyright © 2011-2022 走看看