Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/7b5249587487d84dcbaafcbb6d1155d6 to your computer and use it in GitHub Desktop.
Save peter279k/7b5249587487d84dcbaafcbb6d1155d6 to your computer and use it in GitHub Desktop.
TQC+ JAVA
public class JPA05 {
public static void main(String[] argv) {
int[] data = {2, 4, 3, 5, 7, 6, 9, 1}; // 為排序的資料
int j = 0;
while(j < data.length-1) {
for(int index=0;index<data.length-1;index++) {
if(data[index] > data[index+1]) {
int temp = data[index];
data[index] = data[index+1];
data[index+1] = temp;
}
}
show(data);
j++;
}
}
public static void show(int []data) {
String str = " ";
for(int index=0;index<data.length;index++) {
if(index != data.length-1) {
str += data[index] + " ";
} else {
str += data[index];
}
}
System.out.println(str);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment