Created
May 24, 2017 19:48
-
-
Save peter279k/7b5249587487d84dcbaafcbb6d1155d6 to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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