Skip to content

Instantly share code, notes, and snippets.

@hiroism007
Created April 24, 2013 15:27
Show Gist options
  • Save hiroism007/5453002 to your computer and use it in GitHub Desktop.
Save hiroism007/5453002 to your computer and use it in GitHub Desktop.
選択ソート
public class Sort {
static int[]testNumbers;
public static void main(String[] args) {
testNumbers = new int[10];
for (int i = 0; i < testNumbers.length; i++) testNumbers[i] = (int) (Math.random() * testNumbers.length + 1);
for (int i :testNumbers) System.out.print(i);
for (int i = 0; i < testNumbers.length -1; i++){
for (int j = i + 1; j < testNumbers.length; j++){
if (testNumbers[j]< testNumbers[i]){
int t = testNumbers[i];
testNumbers[i] = testNumbers[j];
testNumbers[j] = t;
}
}
}
for (int i :testNumbers) System.out.println(i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment