Math(2)

Math(2)

public static void main(String[] args) {
        System.out.println(Math.floor(-32.8));
        //常数
        System.out.println(Math.PI);
        System.out.println(Math.E);     
        //幂运算pow(2,3)
        System.out.println(Math.pow(2,3));
        Math.random();  //返回0-1,包括0不包括1
        //返回1-10之间的数字[1,10)
        System.out.println(Math.random()*10); //  [0-10)  9.9999999
        System.out.println(Math.random()*10+1); //[1-11)  10.9999999
        System.out.println(Math.random()*9+1); // [1-10)  9.9999999 

        //数值范围是[x-y) Math.random*(y-x)+x

        //****彩票的例子
        int num[]=new int[7];
        for (int i=0;i<7;i++)
        {
            num[i]=(int)(Math.random()*10);
            System.out.print(num[i]);
        }


    }

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted on 2015-04-27 14:03  MrCharles在cnblogs  阅读(116)  评论(0编辑  收藏  举报

导航