1、源代碼
package?BaiDdu;import?java.util.*;
public?class?test_2_24
{
public?static?void?main(String[]?args)?{
int?num[]=new?int[10];
Random?random=new?Random();
?for?(int?i?=?0;?i?<?10;?i++)?{
?int?n=random.nextInt(100);
while(n<10||n>99)?//判斷是不是兩位數
n=random.nextInt(100);//不是就重新生成
num[i]=n;//放進數組裏
}
?System.out.print("生成數組:");
?for?(int?i?:?num)?{
System.out.print(i+"?");
}
?Arrays.sort(num);//數組排序
?System.out.print("排序後:");
?for?(int?i?:?num)?{
System.out.print(i+"?");
}
}
}
2、運行效果