基礎知識點複習——數組高級應用

現在有兩張撲克,左手拿着黑桃10,右手拿着紅桃K,要求,換過來輸出,最後實現
左手拿着紅桃K,右手拿着黑桃10。


冒泡排序


package bdqn;


import java.util.Scanner;


public class Test05 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[10];
score[0] = 59;
score[1] = 73;
score[2] = 96;
score[3] = 85;
score[4] = 60;

System.out.println("請輸入要插入的成績:");
score[5] = input.nextInt();
for (int j = 0; j < score.length; j++) {
for (int i = 0; i < score.length-1; i++) {
if (score[i+1]>score[i]) {
int temp = score[i];
score[i] = score[i+1];
score[i+1] = temp;
}
}
}
for (int i : score) {
if(i!=0){
System.out.print(i+"\t");
}
}

}
}


2.Arrays工具
.sort()方法:將指定數組進行升序排列





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章