[CODE]public class Compositor {
public static void main(String[] args) {
int[] numbers = {2,3,12,354,1,23,42,123,24};
boolean change = false;
for(int i = numbers.length , temp = 0;i > 0;i--){
for(int j = 0;j < i - 1;j++){
if(numbers[j] > numbers[j+1]){
temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
change = true;
}
}
if(!change){
break;
}
}
for(int number:numbers){
System.out.println(number);
}
}
}[/CODE]
呵呵,我也来发一个,不过这是讲究可读性的版本,其实可以写出更简单的:-)
public static void main(String[] args) {
int[] numbers = {2,3,12,354,1,23,42,123,24};
boolean change = false;
for(int i = numbers.length , temp = 0;i > 0;i--){
for(int j = 0;j < i - 1;j++){
if(numbers[j] > numbers[j+1]){
temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
change = true;
}
}
if(!change){
break;
}
}
for(int number:numbers){
System.out.println(number);
}
}
}[/CODE]
呵呵,我也来发一个,不过这是讲究可读性的版本,其实可以写出更简单的:-)
向雨之傷