import java.io.* ; // input output 資料函式引入
5 ^2 `5 Z# T- n" O& e+ R! ^- t$ e* F9 L% U
import java.util.Arrays ;
! c) e, @, m' N: p' i7 ?0 A8 C
6 m; _4 m* f3 x& u' g* _2 W+ u4 C0 n
1 r( L3 A8 u- x N8 M
public class JVD103{
5 P5 Z* F" U* _# d/ O5 g4 f6 |& Q" Q9 x/ s6 n7 g
& L6 z8 ?) I$ ?* Z
n) L5 l* Z- Z& u1 p( Y: i: O
public static void main(String arg[]){) a L4 Q; g: Y( J) r
6 T1 \. z2 Q9 T+ w4 P( s
( ~3 u3 R- c6 Z& Z+ y3 l3 M" d6 k# W8 n1 s0 e6 i Q7 Z
7 y* n. W2 Y" T+ y5 k. k0 u$ j! D
0 L0 o# g1 e- d( {3 _& C/ d1 r
System.out.println("請輸入欲產生之亂數個數:");+ R/ f- r) {, j/ X+ _0 ?6 Y
l% {7 J7 U- p3 I5 x
5 I# I3 C! W/ b; z7 C6 y3 c s
, H1 C! N+ I4 c x+ [4 K' i0 z int n = 0; //輸入要產生亂數個數 並初始化
! g5 q& p+ a5 l1 p* e
; |9 l0 ]+ k. d 9 D/ \0 b# p- {1 c3 T
& D$ ]4 O3 ?# t2 j //使用到io 一定要加上 try catch9 B, c+ Q: N7 I: d
' z6 ?# i8 e: d' ? try{
3 s$ ?3 Z" G: Y3 E+ L9 I. [; D4 f7 V: @- H, s2 r) X/ f+ [8 e' S3 u
InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流
# k) B9 \& j: L& ~, C
( v v. X5 O5 a$ V1 v BufferedReader br = new BufferedReader(isr); //資料暫存區; _# ]/ y4 ?# f; x, L4 K
) `) W2 S" b* }' d' k! N
n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)
+ F2 r2 Z% U) A( u+ i* `6 \
% r9 n: Q6 [) ?5 h1 b2 u }catch(Exception e){}
n: @0 ^% x: d+ m
- K1 m/ W5 A" r+ S ' w& |6 N5 ^/ C: x% j# G
2 S* d3 r% c4 {3 G 8 ]7 L# ]1 s- y' o8 X
' x( k) c M% V2 Q9 e! q0 n int Num[] = new int[n];//產生n個亂數的變數
5 V Q; ~2 {' N& t' q& k
+ n1 R' o) @3 s2 \' Q! ]. o * H2 w; k& a, f: L
- z" S8 w6 t0 q9 O) ~
for(int i=0;i<n;i++){1 Y' A& L2 l# v0 F
' A' z C8 Y# p/ V, I Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
: Q X* K1 o1 A$ ]: P9 }, D$ s6 B
$ t5 i" V) y5 {9 i //System.out.println(Num[i]);
' j/ F. {3 W5 q' j" H/ z1 H4 n' i% `( ]7 m# R4 j
}
% J8 v4 r0 m9 _6 X% p% [; [6 ?5 U1 y" K/ h l1 r a
Arrays.sort(Num); //排序- y' a( _( s0 o; G$ d
, Y* i7 l( w/ m$ n/ M
i4 g( s% n4 @+ J
4 k; S: o: L% _& r- o //輸出
. J4 u8 m. V2 z/ t( m( l" R1 |( M* ^* W+ R7 i
for(int i=0;i<n;i++){
- b7 o4 V- u& G3 a9 q) x W. w( O, b% Q$ E
System.out.print(Num[i]+"\t");
: q9 Y3 M& I5 k
: X) P7 C3 g! {" u0 G }$ B) D6 O4 p( G& Q' c
c- k/ p: [3 { \: F D
. P. q |2 X" ^3 K* c# r/ }
% e$ V1 T3 _% y' [; h2 M
}7 g2 ?$ C n( D' ]5 t
$ `9 k3 {& N3 @1 p: l7 x- l7 F/ h& H @
/ G) B8 u1 a5 e' h! ~" D
} |