网站建设相关语言,黄岛网站制作,天津网站域名购买,网页设计与编程Math#xff1a;
概述#xff1a; Math 包含执行基本数字运算的方法 调用方式#xff1a; Math类中无构造方法#xff0c;但内部的方法都是静态的#xff0c;可以通过 类名.进行调用 常用方法#xff1a;
方法名 方法名说明public static int abs(int a)返回参数的绝对…Math
概述 Math 包含执行基本数字运算的方法 调用方式 Math类中无构造方法但内部的方法都是静态的可以通过 类名.进行调用 常用方法
方法名 方法名说明public static int abs(int a)返回参数的绝对值public static double ceil(double a)返回整数向上取整public static double floor(double a)返回整数向下取整public static int round(float a)返回整数四舍五入public static int max(int a,int b)返回两个int值中的较大值public static int min(int a,int b)返回两个int值中的较小值public static double pow (double a,double b)返回a的b次幂的值public static double random()返回值为double的正值[0.0,1.0)
演示 public static void main(String[] args) {// 返回参数的绝对值System.out.println(Math.abs(-10));// 返回整数向上取整System.out.println(Math.ceil(10.9));// 返回整数向下取整System.out.println(Math.floor(10.9));// 按照四舍五入返回最接近参数的intSystem.out.println(Math.round(10.2));// 返回两个int值中的较大值System.out.println(Math.max(10, 20));// 返回两个int值中的较小值System.out.println(Math.min(10, 20));// 返回a的b次幂的值System.out.println(Math.pow(2,3));// 返回值为double的正值可以生成随机数范围是[0.0,1.0)System.out.println(Math.random());}
System
概念 System类代表系统系统级的很多属性和控制方法都放置在该类的内部。该类位于java.lang包。 System类的常用方法 :
方法名说明public static void exit(int status)终止当前运行的 Java 虚拟机非零表示异常终止public static long currentTimeMillis()返回当前时间(以毫秒为单位)public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)数据源起始索引目的地数组起始索引拷贝个数public static void main(String[] args) {// public static void exit(int status) 终止当前运行的 Java 虚拟机非零表示异常终止0表示正常停止System.exit(0);System.out.println(执行1了吗);System.exit(1);// public static long currentTimeMillis() 返回当前时间(以毫秒为单位)System.out.println(System.currentTimeMillis());// 还能用作计算时间计算fori循环用时long start System.currentTimeMillis();for (int i 0; i 100000; i) {System.out.println(i);}long end System.currentTimeMillis();System.out.println(end - start);// 数组拷贝int [] arr1 {1,2,3,4,5};int [] arr2 new int [10];// arraycopy数据源起始索引目的地数组起始索引拷贝个数System.arraycopy(arr1,0,arr2,0,arr1.length);for (int i 0; i arr2.length; i) {System.out.println(arr2[i]);}// 把arr1最后两个索引拷贝到arr2最后两个索引// 起始索引直接写8也可以System.arraycopy(arr1, 3, arr2, arr2.length - 2, 2);for (int i 0; i arr2.length; i) {System.out.println(arr2[i]);}}