import java.io.* ; // input output 資料函式引入
% I) T6 K) _% @4 i7 N* ?2 M% n$ G. {" W) [( o6 ]
import java.util.Arrays ;
- Q. d0 V8 R' X& l+ Q
S/ q: R" K3 G2 J4 c
: W- p6 H4 [6 T* w% ^) E1 M% }4 j6 d3 F3 G8 h
public class JVD103{
: n8 U9 V# f1 U- x. Y5 Y- Z0 ]( K: x! `3 u6 c' I, B- q1 I
5 q! J" v6 N* w! N. }9 ^1 [% Z4 `# b0 `5 L
public static void main(String arg[]){
/ Q1 P0 n# g; l1 I8 T
" z3 v# V6 C1 n& s+ a, R' A : a$ f6 r. h0 u! T# i& k
! e. Y _* L/ A# E
1 @# G# j! R3 P) M" l5 I: ?9 z
4 N5 T/ H) h" P! X5 r System.out.println("請輸入欲產生之亂數個數:");
, L# E, p% }/ ]) S7 x
2 O8 e( f8 p+ @' E
, m) K5 r: o; I S4 @& M# ]5 c: [8 g' z
int n = 0; //輸入要產生亂數個數 並初始化; V/ A5 t' j* Q+ t" a5 I2 \
7 M4 ]2 J5 w. e
. Q( B% s# P6 s7 Z7 `8 T
5 Q$ x, [* g4 N6 A2 |3 t //使用到io 一定要加上 try catch, o: s* i* b, |9 y2 M
F2 M/ |7 K' F# R try{% B2 T* `. x- u
* {1 k% [9 ]8 ~' {% O) e1 n" C
InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流9 s0 L& a5 T, t1 G
T2 }9 ]5 R6 N: X BufferedReader br = new BufferedReader(isr); //資料暫存區
) H7 \; B/ d( I0 N+ a/ D
' S2 H5 r2 B$ u; B' o n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)1 W+ Y, k' R, L6 C' M$ [0 |5 D( B6 d
* k1 a; D2 \- T% L" B/ N# Z" Z }catch(Exception e){}' I) k8 Z Z# t8 @1 f
- v" s. [# L, T" S$ z
7 }7 A9 d; U% z7 y% v) u0 c+ x/ p. W( t" m
/ p b- G$ l7 r- d
6 _4 R" R! i, t# m9 |$ Z: x+ T' Q
int Num[] = new int[n];//產生n個亂數的變數1 b9 L) P1 j2 s- ?0 A
, |6 V4 X) j. {
& h3 E0 h* T7 D; H: x$ m0 Y2 f# N* x) E0 z r+ E, j
for(int i=0;i<n;i++){
+ e( W/ z& O7 q# I4 t# S7 Y0 C& P
/ w6 p' Y8 _- S3 D Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
7 n: ^$ J; N1 F: P; b, w3 Y+ C4 _$ U1 D( \% Q+ F% D ^
//System.out.println(Num[i]);' ?+ s$ M! o! [! k
v8 y/ `+ _- r- M" T
}1 ?4 }! L3 m9 y6 G* S2 X: m7 l
% |- l9 {# ?+ T Arrays.sort(Num); //排序
% T1 V `$ i. \6 @( m$ N* U0 r
. [* L3 X V1 f: |* Y
8 m' U- A0 u5 @1 |
Q/ x7 N8 f0 o% n( X# R //輸出
) c- C8 c5 G3 q5 H7 L+ A/ P. ?$ J, K1 F3 H9 ]9 r, N
for(int i=0;i<n;i++){
9 \* c' Y. B5 i& t4 R* m' ]& L
3 }# o! k( i& }4 K; p- `7 h" J+ s/ B System.out.print(Num[i]+"\t");
5 H a: F9 \' }' K4 z6 k7 H: Z3 K8 J( y6 Q4 D: Y
}
+ x2 Z. h0 Z0 x; a m( y2 Y, A, ^- ?" r2 y
7 E# p. u2 q/ D, d2 }: P
7 p" E! v' e& j9 l" _% d }. }7 J& n4 {% P% R/ H
$ M/ ]3 G5 N) j. j w) ?+ }. t7 ?0 w8 d
; t; T, l6 [, [ w% Z; g3 t} |