在嘗試對學生對象進行排序時出現了inreachable code的錯誤,怎么回事???
package com.imooc.collection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class CollectionsTest {
/*
* 通過collections.sort方法對泛型為Integer的List進行排序
*/
public void testSort1(){
//創建名為integerList的List列表
List<Integer> integerList = new ArrayList<Integer>();
//往integerList中插入10個100以內不重復的隨機數
//Random類的實例用于生成偽隨機數流
Random random = new Random();
Integer k;
for(int i = 0;1 < 10;i ++){
//判斷integerList中是否包含隨機數k
do{
k = random.nextInt(100);
}while(integerList.contains(k));
integerList.add(k);
System.out.println("成功添加整數 ?"+k);
}
System.out.println("------排序前-----");//編譯器在這兒出現inreachable code 的錯誤?。?/p>
//遍歷integerList中的元素
for (Integer integer : integerList) {
System.out.println("元素"+integer);
}
//調用Collections.sort()方法進行排序
Collections.sort(integerList);
System.out.println("------排序后");
for (Integer integer : integerList) {
System.out.println("元素啦啦啦"+integer);
}
}
public static void main(String[] args) {
CollectionsTest il = new CollectionsTest();
il.testSort1();
}
}
結果是這樣的?。。。?!
Exception in thread "main" java.lang.Error: Unresolved compilation problem:?
Unreachable code
at com.imooc.collection.CollectionsTest.testSort1(CollectionsTest.java:27)
at com.imooc.collection.CollectionsTest.main(CollectionsTest.java:42)
2016-12-12
你的for(int i=0;i<10;i++);寫成了1<10了,應該是i,i,i