public static void main(String[] args) {
String[] arr = {"nba","abc","cba","zz","qq","haha"};
for(int i = 0; i < arr.length-1; i++){
for(int j = i + 1; j < arr.length; j++){
if(arr[i].compareTo(arr[j]) > 0 ){
String temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.print("[");
for(int i = 0; i < arr.length; i++){
if(i != arr.length -1 ){
System.out.print(arr[i] + ", ");
}else{
System.out.print(arr[i] + "]");
}
}
} |
|