zoukankan      html  css  js  c++  java
  • 随机数Random和静态函数Math

    随机数 (Random) 通过种子的伪随机。

    线性求余算法

    如果参数不填,默认种子是时间

    下面代码中有Math的一些常用方法

     1 public class Demo01 {
     2 
     3     public static void main(String[] args) {
     4         
     5         
     6         Random random=new Random();
     7         int s=random.nextInt(10);
     8         System.out.println(s);
     9         
    10         //求绝对值
    11         System.out.println(Math.abs(-2));
    12         
    13         //浮点型保留2位小数
    14         System.out.println(String.format("%.2f", Math.PI));
    15         
    16         double a=-2.3;
    17         //向上取整    没有有四舍五入
    18         System.out.println(Math.ceil(a));
    19         //向下取整    没有有四舍五入
    20         System.out.println(Math.floor(a));
    21         //最近取整,有四舍五入
    22         System.out.println(Math.round(a));
    23         
    24         //求幂  返回double类型
    25         System.out.println(Math.pow(3, 4));
    26         
    27         //求立方根 
    28         System.out.println(Math.cbrt(27));
    29         //求平方根
    30         System.out.println(Math.sqrt(25));
    31         
    32         //求最大值
    33         System.out.println(Math.max(23, 45));
    34         //求最小值
    35         System.out.println(Math.min(23, 45));
    36         
    37         System.out.println(Math.nextAfter(5.1, 7.2));
    38         
    39 
    40     }
    41 
    42 }
  • 相关阅读:
    Numpy数据处理函数
    数据库-创建表
    描述统计学:表格法和图形法
    最短路 || POJ 1511 Invitation Cards
    搜索 || DFS || UOJ 146 信息传递
    最短路 || UOJ 19 寻找道路
    最短路 || POJ 1847 Tram
    博弈论
    筛选法 || POJ 3292 Semi-prime H-numbers
    团队第一次作业
  • 原文地址:https://www.cnblogs.com/sunzhiqiang/p/11728814.html
Copyright © 2011-2022 走看看