数学运算

    

package com.hanqi;

       import java.util.Random;

         public class math {

         public static void main(String[] args) {

//数学运算
    System.out.println("四舍五入="+Math.round(123.556));
    //取上限值       大于或等于 数值的最小整数
    System.out.println("取上限值"+Math.ceil(123.456));
    //取下限值        小于或等于数值的最大整数
    System.out.println("取下限值"+Math.floor(123.456));
    
    
    System.out .println("PI="+Math.PI );
    
    
//随机数
    System.out.println("随机数="+Math.random());
    System.out.println("随机数="+Math.random());
    System.out.println("随机数="+Math.random());
    System.out.println("随机数="+Math.random());
    System.out.println("随机数="+Math.random());
    System.out.println();
    System.out.println();
    System.out.println();
    
    
    
    Random r=new Random();//用时间
    
    r.nextInt(100);
    
    
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));


    System.out.println();
    System.out.println();
    System.out.println();
    
    
    r=new Random(1);//随机数种子

    
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    System.out.println("随机数="+r.nextInt(100));
    }
    

}

 

posted @ 2015-12-17 08:38  琦仔  阅读(179)  评论(0编辑  收藏  举报