简单的字符排序问题

	public static void main(String[] args) {
		String[] trs ={"and","zuo","for","we","be","you"}; 
		sort(trs);
		for(int i=0;i<trs.length;i++){
			System.out.println(trs[i]);
		}
	}
	public static void sort(String[] str){
		for(int i=0;i<str.length-1;i++){
			String maxStr = str[i];
			int index = i;
			for(int j=i+1;j<str.length;j++){
				if(maxStr.compareTo(str[j]) < 0){
					maxStr = str[j];
					index = j;
				}
			}
			str[index] = str[i];
			str[i] = maxStr;
		}
	}

你可能感兴趣的:(String)