flydog123456
发贴: 4
积分: 0
|
于 2004-11-03 15:54
public class invertArray{ public static void main(String args[]){ int i,j; String strArray[] = {"about","abandon","do","can","here","my","go"}; int k = strArray.length; System.out.println("Resource string array is:"); for(i = 0;i < k;i++) { System.out.print(strArray[i]+" "); } System.out.println("\n************************************"); for(i = 0;i<k-1;i++) { for(j = i+1;j < k;j++) { if(strArray[i].compareTo(strArray[j])<0) { String tempStr = strArray[i]; strArray[i] = strArray[j]; strArray[j] = tempStr; } } } System.out.println("Result after sortting is:"); for(i = 0;i < k;i++) { System.out.print(strArray[i]+" "); } } }
输出结果是: resource string array is: about abandon do can here my go ***************************************** result after sorting is: my here go do can about abandon
我不明白 " for(i = 0;i<k-1;i++) { for(j = i+1;j < k;j++) { if(strArray[i].compareTo(strArray[j])<0) { String tempStr = strArray[i]; strArray[i] = strArray[j]; strArray[j] = tempStr; } } } " 这个语句是什么意思啊????是排序吗?是按什么顺序排的啊? 如果不是 那后面的输出的结果是什么意思???? 希望高手指点啊 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(首先确定这个程序没有错!!)
|