當前位置:編程學習大全網 - 網站源碼 - 讓計算機隨機產生出10個兩位正整數,然後按照從小到大的順序顯示出來 java語言

讓計算機隨機產生出10個兩位正整數,然後按照從小到大的順序顯示出來 java語言

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、運行效果

  • 上一篇:Rsi通道源代碼
  • 下一篇:關於VHDL中ALU裏的移位運算和乘法運算?
  • copyright 2024編程學習大全網