import java.io.* ; // input output 資料函式引入# J$ d+ J: o3 K4 T
( L! C6 _7 F3 j1 g+ Y% _0 ~% Y
import java.util.Arrays ;
& ^! `3 q& l- s, X S% N. n/ L6 _7 P' y! i+ w1 q
7 B+ D+ F2 G* `+ Z+ W4 |% [
+ M, w' ^+ s8 ~public class JVD103{. J" `& x/ u1 K
( ]: O7 ~% H' f r
8 r. J( W' ^+ N) m* \+ l3 H0 ]5 c2 a; J
public static void main(String arg[]){ |8 C& f' a! z
7 j+ X* h& _' L
/ i) y- u5 F2 O. `& w3 I! }) ~! J* R; {7 N, w' M' f t2 g
3 D7 I: ?" _& W4 M' T1 \. T/ w+ @
System.out.println("請輸入欲產生之亂數個數:");9 R" M3 s" w! N- r7 ?+ v
4 J$ y! r, v- m% `; h4 `) _
8 |% r5 F3 V& t* [+ {! J
5 S2 D2 p& Y( i4 n6 O int n = 0; //輸入要產生亂數個數 並初始化
3 Z# T' m8 u, ]3 B: r8 l: e' Q9 ^7 h' G" I* x7 O! [! O! g
' _- R2 J9 ~( k2 S$ n1 W8 |
' Z. S# s: `0 u9 s0 y1 P) D //使用到io 一定要加上 try catch$ ]6 {7 n6 l9 ]5 X
6 I; c5 l. v* _
try{
j) V/ f+ g2 \8 V; e1 w; y0 P3 k3 p" t: q# v3 a( a
InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流2 m: k+ q7 l4 b! P* w8 l% {
: k- v+ l( C# o
BufferedReader br = new BufferedReader(isr); //資料暫存區: F. h# Q G4 ?
% g, P, L5 E8 a) c* W' \( N) d, |; _
n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)6 j' H G' R. P1 R7 d
[4 E( ^2 f: d0 x% A9 K) Q9 D( u }catch(Exception e){}$ X! \& z# n, m( P% B A, K1 W
% E8 P: b, s( ?7 r: J) @5 O+ M
0 J; y7 y! ^! p! c6 }
8 J9 C/ s' `. G6 F, _7 F , j: t9 j2 T4 n2 Z
* g# q% s5 ?8 f' b1 y/ ~ int Num[] = new int[n];//產生n個亂數的變數
& h) R, G, Q! t- F# N" {
6 Y. \; K" t3 b. G" Z
% P/ ?" p$ T6 \
5 R; d9 O6 V& |# V' c/ \ for(int i=0;i<n;i++){; `1 s1 }( |+ A0 |
& [' Q. h6 f5 ^ Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)7 f" e6 q: F# g* g- e
/ {& }6 @. K5 j8 I$ X7 Y8 Z //System.out.println(Num[i]);5 X6 r5 @9 L8 \& {( S
7 q- ?+ w3 N- g2 W% `
}
3 G/ `7 f/ ?4 O) W4 w/ Y; P G& O
Arrays.sort(Num); //排序" w' w& |; w8 p' H! w' ^
, a: F3 ?2 q5 q0 r 5 m6 a$ z/ \6 X! I" w" H7 C
. m( s3 W6 q: a! p& y1 |, G
//輸出
0 ~4 R( G7 o& x$ j$ ?/ z, U# H; E/ S0 y
for(int i=0;i<n;i++){
' l+ P0 X5 v }
1 q5 c& W7 K3 `1 I* F* s/ O System.out.print(Num[i]+"\t");
& ]/ \0 b# v! y A: G1 `# K/ m- X: @" c# `3 B& g
}
1 f5 d3 o3 T; y) L4 w/ T" ?9 W8 m0 g2 Z4 ?4 `% G
+ j8 x, Z! ?# g' Q$ @. s; j1 Z. s7 q6 V; [* b" N
}
6 Z2 G& M- i8 P# d+ X% I* P. ?
+ [8 q$ a) J. _) z# q% M. E2 l) h9 C
2 H; P ]) E) p8 k9 F5 G} |