Java中的math类的常用方法及用法说明
2017-06-24 07:38
477 查看
package java5;public class MathNum {public static void main(String[] args){double a=12.81;int b=(int)a;System.out.println("强制类型转换:"+b);long c=Math.round(a);//调用round方法,四舍五入System.out.println("四舍五入:"+c);double d=Math.floor(a);//调用floor方法,返回小于参数的最大整数System.out.println("floor:"+d);double
e=Math.ceil(a);//调用ceil方法,返回大于参数的最小整数System.out.println("ceil:"+e);double x=Math.random();//调用random方法,产生[0.1]之间的随机数浮点数System.out.println("随机数:"+x);int y=(int)(Math.random()*99);System.out.println("产生[0,99]之间的随机整数:"+y);int[] nums = new int[10];// 定义一个整型数组,长度为10
for (int i = 0; i < nums.length; i++) { //通过循环给数组赋值 int z = (int)(Math.random()*10);// 产生10以内的随机数nums[i] = z;// 为元素赋值}for (int num:nums) {// 使用foreach循环输出数组中的元素System.out.print(num + " ");}}}
e=Math.ceil(a);//调用ceil方法,返回大于参数的最小整数System.out.println("ceil:"+e);double x=Math.random();//调用random方法,产生[0.1]之间的随机数浮点数System.out.println("随机数:"+x);int y=(int)(Math.random()*99);System.out.println("产生[0,99]之间的随机整数:"+y);int[] nums = new int[10];// 定义一个整型数组,长度为10
for (int i = 0; i < nums.length; i++) { //通过循环给数组赋值 int z = (int)(Math.random()*10);// 产生10以内的随机数nums[i] = z;// 为元素赋值}for (int num:nums) {// 使用foreach循环输出数组中的元素System.out.print(num + " ");}}}
相关文章推荐
- Java中Math类的常用方法
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Java:Math类中的常用方法
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Java中Math类的常用方法
- JAVA并发库之Executors常用的创建ExecutorService的几个方法说明
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Java中Math类的常用方法
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Java的SimpleDateFormat常用方法说明整理
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Java中Math类的常用方法
- Java中Math类的几种常用方法
- java-reflect 常用方法说明及实例
- JAVA常用关键字及其用法简要说明
- Java的SimpleDateFormat常用方法说明整理(转)
- java并发库之Executors常用的创建ExecutorService的几个方法说明
- Math类常用方法(Java)
- Java第四周常用类与集合框架上机实验二学会Math类常用方法使用