zoukankan      html  css  js  c++  java
  • Math类的常用方法

    System.out.println("返回参数的绝对值:" + Math.abs(-9)); //9
    //ceil天花板的意思,就是返回大的值,注意一些特殊值
    System.out.println("对整形变量向上取整,返回类型为double型:" + Math.ceil(-8.7)); //-8.0
    System.out.println(Math.ceil(8.7)); //9.0
    System.out.println(Math.ceil(8.1)); //9.0
    //floor地板的意思,就是返回小的值
    System.out.println("对整型变量向下取整。返回类型为double类型:" + Math.floor(-8.1)); //-9.0
    System.out.println(Math.floor(8.9)); //8.0
    //rint 四舍五入,返回double值 (注意.5的时候会取偶数 )
    System.out.println("返回与参数最接近的整数。返回类型为double: " + Math.rint(4.5)); //4.0
    System.out.println(Math.rint(11.5)); //12.0
    System.out.println(Math.rint(10.5)); //10.0
    //round 四舍五入,float时返回int值,double时返回long值
    System.out.println("返回一个最接近的int、long型值:" + Math.round(5.5)); //6
    // random 取得一个大于或者等于0.0小于不等于1.0的随机数
    System.out.println("返回一个随机数:"+Math.random());

  • 相关阅读:
    c++链表实现学生成绩管理系统(简易版)
    IOS动画讲解
    栈的实现
    Masonry的使用
    二叉树详解-2
    二叉树详解-1
    CoreData的使用-2
    NSPredicate 详解
    CoreData的使用-1
    IOS常用手势用法
  • 原文地址:https://www.cnblogs.com/gaomanito/p/8311024.html
Copyright © 2011-2022 走看看