Java第五天

2018-12-16  本文已影响0人  啦啦啦_9a5f

static(静态)关键字

既可以修饰成员方法也可以修饰成员变量

代码块

Java API定义的静态类为工具类,将构造方法私有化,无法声明对象,无法访问类中的内容和成员、成员变量没有关系。

Math.ceil(1.2)//2.0 天花板 向上取整

Math.floor(1.2)//1.0 地板 向下取整

static long round(double a)//四舍五入

Math.round(1.2)\\1

Math.round(1.6)\\2 返回的数值为整型

Math.random()//返回一个随机数,大于0小于1

自定义工具类

public class MyArrays{

  private MyArrays(){}

  public static int getMax(int[] arr){

    int max = 0;

    for(int x  = 0; x<arr.length;x++){

        if(arr[x] > max){

            max = arr[x];

          }

      } 

    return max;

  }

}

上一篇 下一篇

猜你喜欢

热点阅读