import java.io.* ; // input output 資料函式引入
' y9 E/ V! a$ e% k& Y) l" f) M" p2 H; f, e
import java.util.Arrays ;/ \- C$ D9 k2 r
0 M' y2 @5 @+ z0 N! `1 X: h
( a% P$ ~ g- a: J) [
! f. n8 o7 u( v3 V# k: Bpublic class JVD103{
3 D- d0 Y- }' {
' `; M: l0 L* o/ q1 N; Z7 P ? |9 `% c- {: h7 a
; R7 z; Y% _* ]0 P- H public static void main(String arg[]){7 L" y$ L4 r* U" ]0 D2 t, I8 `% o- P
$ I7 a+ K8 ~& B: z
, A: [; m' h, n+ K N1 h' W
' C, ~0 X; M+ |* p& R$ o2 D 3 U7 }5 J( Z( H' _
% ?. p0 L1 C9 I0 T7 H System.out.println("請輸入欲產生之亂數個數:");
/ X) g- |# ~: t3 L$ G; C; [8 I3 Q7 F8 t# |: q3 y
& q# M: f. q- D6 n: v" K2 j+ N& ? C
2 H4 [# g* l# U- }# x3 G: }7 t0 F int n = 0; //輸入要產生亂數個數 並初始化/ c0 G$ s+ t0 N5 O6 b9 _4 e
, i( o' Q7 n9 N8 Y" N5 @& A
: Z$ n' n6 M3 l
. B4 b7 O2 ^. o( i& j
//使用到io 一定要加上 try catch
# N; V+ K% @& i/ L, b8 [) t4 p$ \/ M' z6 u. m+ T4 K
try{6 C1 @' w% \5 C2 A8 z" \
) e, o6 ]- n- d* m, u InputStreamReader isr = new InputStreamReader(System.in); //輸入資料流0 D9 A' ^3 E" b
9 `/ e, Z/ |; s8 F! j8 Y6 _ BufferedReader br = new BufferedReader(isr); //資料暫存區
, |3 J! ]$ y4 f9 c: R
7 u# Y: D4 ]1 i7 \$ o n = Integer.parseInt(br.readLine()); //輸入的資料是String 但我們要的n是int (轉換)5 M9 ^, E2 g+ O" R
5 j2 g; W9 L- u" g2 m# D8 r- n }catch(Exception e){}
5 _ Z( U7 h1 g
5 K* \9 r1 P ]# @) A9 i & q @4 n, G& ^+ v% @( L4 M
+ E# E* N7 c' f2 U5 z3 ~/ r
) V# b* u) h2 D% Q4 A
+ Z3 k% N' c- T4 g E9 A int Num[] = new int[n];//產生n個亂數的變數3 A; ~7 G0 r+ L5 w* A: D; m
; k; J' v5 g) V9 M+ J' X
% s! g/ r/ |) w% d H
. `# _( |2 t. f m9 n
for(int i=0;i<n;i++){4 Y$ ]1 Z4 G5 @2 i+ [0 ^
" u) t# Y5 _8 Q8 {5 ^; I6 ` Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)! h/ y: i1 N, q8 n
/ @1 [- _% Q5 V. Q; P" B
//System.out.println(Num[i]);
/ H g. x2 D, F4 f" Q" Q
0 X( R" L" N4 Z; ?# W0 T h }
: `& ?* P( y& ^4 i& n y& b( B9 k, n" E; V
Arrays.sort(Num); //排序
1 k( X, p2 n+ L' F' {. L' b4 U) w7 T5 a9 D! ?0 r+ v8 D% N% S
8 X0 Z" I# N; H5 R4 U2 B8 w
! `. }7 l: [! G) O, z& u9 \7 c; d
//輸出# Z+ X. L: u* S3 M: X
7 m/ \7 [ H' I8 \ for(int i=0;i<n;i++){
3 Y! m4 D" B3 x# x( X8 R; B4 L9 R1 k' Q! M E" x$ P
System.out.print(Num[i]+"\t");
4 {% U* \. U, ] n2 C: _9 _: u
, A9 t* _$ A! l: E { }
6 m( q; e! R4 d1 Y0 i& T# c6 v% A3 y& c+ v Z
: [. q4 l; m a& ?
% [' m6 C; r5 u }3 b9 r' a' {1 ?5 X" g
! y4 v9 Y# g$ U5 A7 u3 h) S" q8 {
# h# b% t H' X6 E) Q
& S2 _' s- k+ J} |