使用Math类的random方法产生一个随机数,将其转换为字符串,取小数点后三个字符,得到一个“0.xxx”的字符串,再将其转换成double型,对这个数据进行相关计算,使其取值范围在0~~200之间,最后分别调用Math 类的ceil、floor 、sqr等方法,并显示结果

解决方案 »

  1.   

    Double temp=Double.valueOf(String.valueOf(Math.random()).substring(0,5))*200;
     System.out.println(Math.ceil(temp));
     System.out.println(Math.floor(temp));
     System.out.println(Math.sqrt(temp));
      

  2.   


    LS正解Double temp=Double.valueOf(String.valueOf(Math.random()).substring(0,5))*200;
    System.out.println(String.valueOf(Math.random()).substring(0,5));//"0.xxx"
    System.out.println(Math.ceil(temp));
    System.out.println(Math.floor(temp));
    System.out.println(Math.sqrt(temp));