Arrays类
public static String toString(int[] a) :返回指定数组内容的字符串表示形式。
public static void main(String[] args) {
// 定义int 数组
int[] arr = {2,34,35,4,657,8,69,9};
// 打印数组,输出地址值
System.out.println(arr); // [I@2ac1fdc4
// 数组内容转为字符串
String s = Arrays.toString(arr);
// 打印字符串,输出内容
System.out.println(s); // [2, 34, 35, 4, 657, 8, 69, 9]
}
public static void sort(int[] a) :对指定的 int 型数组按数字升序进行排序。
public static void main(String[] args) {
// 定义int 数组
int[] arr = {24, 7, 5, 48, 4, 46, 35, 11, 6, 2};
System.out.println("排序前:"+ Arrays.toString(arr)); // 排序前:[24, 7, 5, 48, 4, 46, 35, 11, 6, 2]
// 升序排序
Arrays.sort(arr);
System.out.println("排序后:"+ Arrays.toString(arr));// 排序后:[2, 4, 5, 6, 7, 11, 24, 35, 46, 48]
}
Math类
-
public static double abs(double a) :返回 double 值的绝对值。
-
public static double ceil(double a) :返回大于等于参数的最小的整数
-
public static double floor(double a) :返回小于等于参数最大的整数
-
public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法)