標籤:當前系統時間 oid pow 最大值 int() arrays 時間 排序 獲得
//冒泡排序
public class MathGroup {
public static void main(String[] args) {
int[] arr= {13,43,25,36,45};
for(int x=0;x<arr.length-1;x++) {
for(int y=0;y<arr.length-1-x;y++) {
if(arr[y]>arr[y+1]) {
int num=arr[y];
arr[y]=arr[y+1];
arr[y+1]=arr[y];
}
}
}
System.out.println("數組排序結果是:");
GeShi(arr);
}
public static void GeShi(int[] a) {
System.out.print("[");
for(int i=0;i<a.length;i++) {
if(i==a.length-1) {
System.out.print(a[i]+"]");
}else {
System.out.print(a[i]+", ");
}
}
}
}
//選擇排序
public class Choolse {
public static void main(String[] args) {
int[] arr= {13,43,25,36,45};
for(int x=0;x<arr.length;x++) {
for(int y=0;y<arr.length;y++) {
if(arr[x]>arr[y]) {
int num=arr[x];
arr[x]=arr[y];
arr[y]=num;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
Math:
public static int abs(int a)
擷取給定資料的絕對值
public static double ceil(double a)
擷取比給定資料大的,最小的double類型整數
public static double floor(double a)
擷取比給定資料小的,最大的double類型整數
public static int max(int a,int b)
擷取兩個數中的最大值
public static double pow(double a,double b)
返回a的b次冪
public static double random()
產生[0.0—1.0)之間的隨機數
public static int round(float a)
四捨五入
public static double sqrt(double a)
正平方根
Random:
public int nextInt()
獲得int範圍內的隨機數
public int nextInt(int n)
System
擷取0到n之間的隨機數[不包含n]
public static void gc()
記憶體回收行程
public static void exit(int status)
終止當前正在啟動並執行Java虛擬機器
public static long currentTimeMillis()
得到當前系統時間與1970-01-01 00:00:00之間的差值的毫秒值
冒泡排序,選擇排序,math,Random,System