zoukankan      html  css  js  c++  java
  • java复习(4)数字处理类

    java本身自带一些封装好的类方便数字问题的处理,review下方便以后使用

    DecimalFormat类 可格式化数字格式,控制输出格式

    Math类 提供三角函数、指数函数、取整函数、最大最小函数、随机数等方法,方便运算

    BigInteger类 提供大整数运算操作

    BigDecimal类 提供大浮点数运算操作

    package re04;
    import java.text.DecimalFormat;
    import java.lang.Math;
    import java.math.*;
    /**
     * Description: 数字类处理
     * 
     * @author weber DateTime 2017年3月20日 下午6:24:03
     */
    public class DigitalTest {
    
        //DecimalFormat 样例
        public static String tryFormat(String s, int value){
            DecimalFormat myFormat = new DecimalFormat(s);
            String ans = myFormat.format(value);
            return ans;
        }
        
        //Math样例
        public static void tryMath()
        {
            double res = Math.sin(Math.PI/2);
            res= 1 + Math.log10(res);
            res = Math.pow(res,res);
            System.out.println(Math.rint(res));
        }
        
        //Random样例
        public static void tryRandom()
        {
            int s=(int)(Math.random()*5);
            System.out.println(s);
        }
        
        //BigInteger样例
        public static void tryBigInteger()
        {
            BigInteger t = new BigInteger("123456789");
            System.out.println(t.multiply(t));
        }
        
        public static void main(String[] args){
            String s="###,###,###";
            System.out.println(tryFormat(s,123456789));
            tryMath();
            tryRandom();
            tryBigInteger();
        }
    }
  • 相关阅读:
    基于决策树和智能搜索系统
    基于神经网络的人工智能系统
    身边的人工智能&人工智能发展史
    Linux简介和环境的搭建
    回来啦
    顺序表
    方格计数
    2000年的1月1日,是那一年的第1天。 那么,2000年的5月4日,是那一年的第几天?
    十三、排序算法
    十二、预处理
  • 原文地址:https://www.cnblogs.com/weberweber/p/6590937.html
Copyright © 2011-2022 走看看