Array和math工具类-Java

Arrays常用方法

  • public static String toString(数组名):将数组转化为字符串
1
2
3
4
5
public static void main(String[] args) {
int[] arrays = {10,20,30};
String string = Arrays.toString(arrays);
System.out.println(string);
}
  • public static void sort(数组):按照默认升序对数组元素排序
1
2
3
4
5
public static void main(String[] args) {
int[] arrays = {20,10,30};
Arrays.sort(arrays);
System.out.println(Arrays.toString(arrays));
}

math工具类

  • public static double abs(double num):获取绝对值
  • public static double ceil(double num);向上取整
  • public static double floor(double num);向下取整
  • public static long round(double num);四舍五入
1
System.out.println(Math.ceil(3.1));//输出4.0