abs? 绝对值
Math.abs(98);
public class demo {
public static void main(String args[]) {
System.out.println(Math.abs(-89));
System.out.println(Math.max(19,20));
System.out.println(Math.min(23,90));
/*
* 四舍五入*/
System.out.println(Math.round(4.9));
System.out.println(Math.round(-100.6)); //负101
/*
返回小于或等于参数的最大整数
*/
System.out.println(Math.floor(4.3));
System.out.println(Math.floor(-4.3));
/*
返回大于或小于参数的最小整数
* */
System.out.println(Math.ceil(-5.5));
System.out.println(Math.ceil(5.8));
}
}
89
20
23
5
-101
4.0
-5.0
-5.0
6.0
Arrarys
import java.lang.reflect.Array;
import java.util.Arrays;
public class demo9 {
public static void main(String[] args) {
int[] arr={18,2,9,0,4,23};
System.out.println(arr);
System.out.println(Arrays.toString(arr));
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
int a= Arrays.binarySearch(arr,23);
System.out.println(a);
arr=Arrays.copyOf(arr,18);
System.out.println(arr.length);
}
}
[I@1540e19d
[18, 2, 9, 0, 4, 23]
[0, 2, 4, 9, 18, 23]
5
18
Calendar
创建初始化比较特殊:Calender 名字=new Calender();
get方法的使用:get(Cander.YEAR);? ? ? ?//获取当前年
get(Calender.WEEK-OF-MONTH);//获取当前月的第几天
add方法的使用:?
add(Calender.year,1);? ? ? //当前年加1
获取当前格式化的时间:
Date d=名字.gettime();
打印d
package fanxing;
import java.time.Year;
import java.util.Calendar;
import java.util.Date;
public class ca {
public static void main(String[] args) {
Calendar s=Calendar.getInstance();
s.set(Calendar.YEAR,9000);
int i = s.get(Calendar.YEAR);
int m= s.get(Calendar.WEEK_OF_MONTH);
System.out.println(i);
System.out.println(m);
s.add(Calendar.YEAR,1);
System.out.println(s.get(Calendar. YEAR));
Date n=s.getTime();
System.out.println(n);
}
}
9000
4
9001
Sun Sep 27 19:42:45 CST 9001
|