冒泡排序,選擇排序,math,Random,System

來源:互聯網
上載者:User

標籤:當前系統時間   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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.