import java.io.* ; // input output 資料函式引入
. P. {" w# R, g! Z8 \! Z& o, [4 h! d( M0 z W
import java.util.Arrays ;
8 P9 R! l% P# S* A5 i, ^. ]0 h) O3 f: ?! d1 e; F
1 i8 v% A0 B) k% @% N
# D& ]1 `7 Y0 U- Q! hpublic class JVD103{
' y- K6 a5 i/ U N: E9 j/ E' ^. G6 O4 @/ x. y
1 c+ O1 L* x$ t: F- o) Q1 M; `" N+ z: b1 [
public static void main(String arg[]){$ l: C! O# j- ?3 g4 ^
$ j# [1 z) K( Y5 N
+ w& v# s7 d: A" H
2 J3 l( S0 l1 p' C# O! A8 N * y; y& |$ O2 u% r
' v! F3 n% h+ v0 r
System.out.println("請輸入欲產生之亂數個數:");0 I! \8 v' s h! o G; k3 S
& Z' l7 P8 w- T. O3 W
5 H9 t0 l6 r4 v" j9 t
$ \9 o5 G; [2 w5 b/ Y7 n% A
int n = 0; //輸入要產生亂數個數 並初始化: _1 c+ D7 B g# l8 N5 w6 S0 I
1 B" @- x" Q% h7 B% c! ?( N
6 ]/ d& W, P! h, n* [& |
8 t5 a* ~3 l6 h5 w. {% s$ W1 _( g( `* ~ //使用到io 一定要加上 try catch- [0 X* D; T$ [. f& l' E/ l
6 F" e% X# ^, H+ }# n4 g" f' I
try{9 }. p9 v* h! U1 l: p& ?% z
5 u$ x' G( X9 U8 s* D7 p InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流
* H8 }# S/ Q7 N& e- W1 z5 z
1 A" |0 I5 _4 l/ ]" F8 s4 d. ^6 \ BufferedReader br = new BufferedReader(isr); //資料暫存區- u7 S0 K1 U! G* e! s) F+ Y
/ F% |1 R2 \' @# b" y+ M L2 A
n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)9 _" |" r H& \6 b& ^# z
; y! U# _4 A8 u7 e& }* {
}catch(Exception e){}+ L# q( k0 o' Q3 t+ E H" i. u
( x/ \( G. d7 a
* R- [ X! O$ Z/ p" g# {# P) F) ?! l" n. f: I
. j8 h% [2 P% C! E: B( \ ^ e7 }" B% D$ p
int Num[] = new int[n];//產生n個亂數的變數
1 H& G# g& n$ _ _. T) ?/ U* {0 S& t" Y" W: A/ M( f
! x" I% K- I# ]1 @& l" K& m
1 U+ L* x0 M, B( f for(int i=0;i<n;i++){+ S4 G+ O- [/ t- P+ U6 {
+ {: v* x3 x, W) ? Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)& J! `% Z- F: p. a+ X8 j
/ @: {& L. W5 M' B //System.out.println(Num[i]);- n; E6 [3 |+ y/ N- M3 z
0 e; b4 Y. o6 y
}
9 Y; q! O |+ d9 l& x
7 j- T* l% e J0 C" P8 _ Arrays.sort(Num); //排序7 _9 x. B, O9 ~1 R) G' N( J7 m9 N- `
5 {3 \ W- H9 o( |% ?; y- R , X- ]4 H9 g/ m
. T# G; Q. K! y0 x# o O
//輸出3 v; l1 y/ j/ U; A$ ~$ d
8 Z' V& |. o: j( L* W for(int i=0;i<n;i++){% Z2 _9 p2 _6 {1 m& h/ @9 W5 V
$ a, i& r3 N9 J6 @# i System.out.print(Num[i]+"\t");
0 g$ h( o) i, |/ P& B4 y @' |* s5 Y" X: [* a" p/ G
}
% x; f; A) s5 x" D6 f1 c7 Q- \6 C. U
: x/ d1 R/ J7 w, F/ L" K
8 L' F8 Q9 i) g* j2 u1 S }
. _/ p# b! p0 H
8 ^3 @* w! o: u0 {! p2 P
1 ^+ u+ x, c$ o( d% g
r. z4 w9 X/ t+ J$ T4 q} |