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();
        }
    }
  • 相关阅读:
    test6
    test4
    test3
    20165321 2017-2018-2《Java程序设计》课程总结
    20165321 实验五 网络编程与安全-2
    20165321 实验五 网络编程与安全
    实验四 Android开发基础
    20165321 实验三 敏捷开发与XP实践
    《深入理解计算机系统》第三章 程序的机器级表示学习
    《文献管理与信息分析》第二章
  • 原文地址:https://www.cnblogs.com/weberweber/p/6590937.html
Copyright © 2011-2022 走看看