返回列表 發帖

1217 使用者輸入值(實作jvd103)

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
3 e) ?) _! |2 a0 H5 D( i
0 I4 z; A6 d8 Q! T6 s程式中可以輸入值2 V1 r. w& r, D8 p+ T$ U
+ {1 q0 ]! I. e/ o. I9 ~  F2 n; W
實際寫出 jvd103
5 s/ p" c# i# N3 ^; G2 B4 `
1 |. s$ _# a; C: g3 f8 l使用io一定要使用 try catch
  1. import java.io.* ; // input output 資料函式引入
  2. import java.util.Arrays ;

  3. public class JVD103{

  4.         public static void main(String arg[]){
  5.        
  6.        
  7.                 System.out.println("請輸入欲產生之亂數個數:");
  8.        
  9.                 int n = 0;  //輸入要產生亂數個數 並初始化
  10.                
  11.                 //使用到io 一定要加上 try catch
  12.                 try{
  13.                         InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
  14.                         BufferedReader br = new BufferedReader(isr); //資料暫存區
  15.                         n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
  16.                 }catch(Exception e){}
  17.                
  18.                
  19.                 int Num[] = new int[n];//產生n個亂數的變數
  20.                
  21.                 for(int i=0;i<n;i++){
  22.                         Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
  23.                         //System.out.println(Num[i]);
  24.                 }
  25.                 Arrays.sort(Num); //排序
  26.                
  27.                 //輸出
  28.                 for(int i=0;i<n;i++){
  29.                    System.out.print(Num[i]+"\t");
  30.                 }
  31.                
  32.         }

  33. }
複製代碼
  1. import java.util.Scanner; //輸出入
  2. import java.util.Arrays;  //陣列

  3. public class jva103{

  4.         public static void main(String args[]){
  5.        
  6.                 System.out.println("請輸入欲產生之亂數個數:");

  7.                 Scanner s = new Scanner(System.in);

  8.                 //System.out.println(s.nextInt());
  9.                
  10.                 int n = s.nextInt();
  11.                 int ar[] = new int[n];
  12.                
  13.                 //產生亂數
  14.                 for(int i=0;i<n;i++){
  15.                         ar[i] = (int)(Math.random()*1000) ;
  16.                         //System.out.println(ar[i]);
  17.                 }
  18.                 Arrays.sort(ar);
  19.                
  20.                 for(int i=0;i<n;i++){
  21.                         System.out.print(ar[i]+"\t");
  22.                 }
  23.        
  24.         }

  25. }
複製代碼

import java.io.* ; // input output 資料函式引入/ D  }% w; K% F6 x6 b2 O

6 V5 [0 k" x- [4 fimport java.util.Arrays ;
8 O/ w3 |1 H3 r0 [! ~6 ^1 d  ]; s8 h: G

4 X$ P+ Q! Z# U. n5 B
& _( k: J) l7 N7 }9 mpublic class JVD103{9 m; \% L: c# C: M# e

1 d1 _3 a1 L/ C9 A2 r9 k6 m% J  G  G1 L6 E

; k, V5 m* j3 L) r+ M        public static void main(String arg[]){
. @+ @6 ^4 {/ R- z0 B" E; g  j9 U. }4 A7 Q" G
        , m# l& L2 Z) C9 w  @7 f
. ]. c6 I- h- h8 K, v1 \+ q
        
, i5 F; Q7 S/ U
! E: Z% G+ s' M# a' u! \                System.out.println("請輸入欲產生之亂數個數:");5 x. `7 O' S. I8 l( @$ G7 h

7 f9 u* s6 ^8 C. Z+ R$ G        
& f. N# u  k% P0 c: j8 V) Q' e
9 H# L  |/ h( K4 b/ |                int n = 0;  //輸入要產生亂數個數 並初始化
+ m3 W  Y8 H9 q, K6 c  Y( d3 u
! {. _1 H3 ^  ?6 y, l0 X& Y2 x$ ~" A# q               
' f2 A) _) i# J4 p% L  e
' L2 j! f- B% e2 R' u" H                //使用到io 一定要加上 try catch2 q- ~6 Y7 B4 |2 S% d- \

5 D7 N) o6 o# [+ m: X" f- f. w                try{
0 ^7 t( S1 U& U: S: b9 }* L9 `0 `7 @  s& e' n; e$ h
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流) N# C8 p( r  e2 ^9 _9 R0 p- |! L
, X8 n$ u+ H8 t- F
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
$ s6 P- l8 ~( x' Y7 v- b5 H3 R- `. ]7 b8 F! _! t- N
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)7 z+ T* ?& q  V) e8 M

7 @- _, w  t+ @/ q                }catch(Exception e){}' g9 F1 F6 ?" t1 ]
' |5 v( ?% m0 L3 {8 s4 f
                ; o7 x# r! m4 T" R

# ~+ j: t) i1 t5 p: z% N4 X4 {  o                8 b% C+ q4 ^' R9 x( U

& d( t$ A' M6 T9 t$ W$ N& d) \$ G                int Num[] = new int[n];//產生n個亂數的變數8 R: B  j) Y0 G0 U+ y$ f* w
  S+ d( q: t8 W7 D* g; c% b7 m
                : {% W" \$ k7 W$ I* {. D! W6 a: C
% O! [' l+ y, P. a
                for(int i=0;i<n;i++){1 y0 C+ M/ i- K/ W' g; x2 e( T

6 I( }$ j$ M0 f% J                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)% o7 C; w; G7 C0 a. Y' ^  i! \" c
3 H$ ]9 j' B5 k9 F- ]% G* [/ |
                        //System.out.println(Num[i]);
, c/ s! B9 x$ r- Q9 x5 U, M: \( [0 o! _& \5 m$ K) P) `
                }) k5 k4 n* U" `; p+ N; h6 _3 i

0 B& h. s. Q7 |                Arrays.sort(Num); //排序
7 }/ r9 @$ H: N) m. U' v
: d4 F% C2 @4 J! k- [$ p, \4 |                * f& d( b- k$ _2 M- Z) P

/ s. V7 o: g6 Y( Q4 i                //輸出
9 m0 F7 L9 C. O$ T$ L6 @) P3 K
* z1 v$ U4 r9 x* B" Y- f                for(int i=0;i<n;i++){
& @& a# J4 v) ]0 y' }- L  s3 A
" W. C8 }. P, y9 ~                   System.out.print(Num[i]+"\t");
- F0 A) C) I- _- Q! a& Y) i7 v3 l$ }/ t5 ]0 U; }" \0 R
                }
' N, r' v- F! B' d
  c1 W7 e& X# Y. ?9 u0 ^! V               
3 D; Q, }6 z- |3 p6 c( G/ R& H/ G& x! R
        }
/ H2 N" ^2 A* X' B/ [) k2 D1 a* y8 F/ P8 b

  Q( ~1 ^- D1 W1 R  _5 g3 O
- L) B( H4 _$ r# N5 O* F9 y}
人平

TOP

  1. import java.io.*; //input output 資料涵式引入
  2. import java.util.Arrays;
  3. public class JVD103{
  4.     public static void main(String arg[]){
  5.         System.out.println("請輸入欲產生之亂數個數");
  6.             int n=0;
  7.                 try{
  8.                 InputStreamReader isr=new InputStreamReader(System.in);  //輸入資料流
  9.                 BufferedReader br=new BufferedReader(isr);  //資料暫存區
  10.                 n=Integer.parseInt(br.readLine ());
  11.                 }catch(Exception e){}
  12.                 int Num[]=new int[n];
  13.                 for(int i=0;i<n;i++){
  14.                     Num[i]=(int)(Math.random()*1000);
  15.                         System.out.println(Num[i]);
  16.                 }
  17.                
  18.                 Arrays.sort(Num);
  19.                 for(int i=0;i<n;i++){
  20.                         System.out.print(Num[i]+"\t");
  21.                 }
  22.         }
  23. }
複製代碼
★ 嘉凱~~☆

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class j103
  4. {
  5.     public static void main(String[]args)
  6.         {
  7.             System.out.println("請輸入欲產生之亂數個數:");
  8.                 Scanner s=new Scanner(System.in);
  9.                 int n=s.nextInt();
  10.                 int ar[]=new int[n];
  11.                 for(int i=0;i<n;i++)
  12.                 {
  13.                     ar[i]=(int)(Math.random()*1000);
  14.             }
  15.                 Arrays.sort(ar);
  16.                 for(int i=0;i<n;i++)
  17.                 {
  18.                     System.out.println(ar[i]+"\t");
  19.             }
  20.         }
  21. }
複製代碼
小雲雀

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class j103
  4. {
  5.         public static void main(String arg[])
  6.         {
  7.                 System.out.println("請輸入欲產生之亂數個數:");
  8.                 Scanner s=new Scanner(System.in);
  9.                 // System.out.println(s.nextInt());
  10.                 int n=s.nextInt();
  11.                 int ar[]=new int[n];
  12.                 for(int i=0;i<n;i++)
  13.                 {
  14.                         ar[i]=(int)(Math.random()*1000);
  15.                         // System.out.println(ar[i]);
  16.                 }
  17.                 Arrays.sort(ar);
  18.                 for(int i=0;i<n;i++)
  19.                 {
  20.                         System.out.println(ar[i]+"\t");
  21.                
  22.                
  23.                 }
  24.         }
  25. }
複製代碼
★ 嘉凱~~☆

TOP

  1. import java.util.Arrays;
  2. import java.util.Scanner ;
  3. public class j103
  4. {
  5.         public static void main(String[]arg)
  6.         {
  7.         System.out.println("請輸入欲產生之亂數個數");
  8.         Scanner s=new Scanner(System.in);
  9.         //System.out.println(s.nextInt());
  10.         int n = s.nextInt();
  11.         int ar[]=new int[n];
  12.                 for(int i=0;i<n;i++)
  13.                 {
  14.                 ar[i]=(int)(Math.random()*1000);
  15.                 }
  16.         Arrays.sort(ar);
  17.                 for(int i=0;i<n;i++)
  18.                 {
  19.                 System.out.print(ar[i]+"\n")       
  20.                
  21.                 }
  22.         }
  23. }
複製代碼
水桶小鄭,鯰魚

TOP

  1. import java.io.*; //input output 資料涵式引入

  2. import java.util.Arrays;

  3. public class JVD103{

  4.     public static void main(String arg[]){

  5.         System.out.println("請輸入欲產生之亂數個數");

  6.             int n=0;

  7.                 try{

  8.                 InputStreamReader isr=new InputStreamReader(System.in);  //輸入資料流

  9.                 BufferedReader br=new BufferedReader(isr);  //資料暫存區

  10.                 n=Integer.parseInt(br.readLine ());

  11.                 }catch(Exception e){}

  12.                 int Num[]=new int[n];

  13.                 for(int i=0;i<n;i++){

  14.                     Num[i]=(int)(Math.random()*1000);

  15.                         System.out.println(Num[i]);

  16.                 }

  17.                

  18.                 Arrays.sort(Num);

  19.                 for(int i=0;i<n;i++){

  20.                         System.out.print(Num[i]+"\t");

  21.                 }

  22.         }

  23. }
複製代碼
人平

TOP

  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3. public class jva103{
  4.     public static void main(String arg[]){
  5.         System.out.println("請輸入欲產生之亂數個數:");
  6.     Scanner s = new Scanner(System.in);   

  7.         int n = s.nextInt();
  8.     int ar[] = new int[n];
  9.     for(int i=0;i<n;i++){
  10.             ar[i]=(int)(Math.random()*1000);
  11.             //system.out.println(ar(i);
  12.                 }       
  13.         Arrays.sort(ar);
  14.                 for(int i=0;i<n;i++){
  15.                     System.out.print(ar[i]+"\t");               
  16.                 }
  17.     }
  18. }
複製代碼
May

TOP

import java.util.Arrays;/ J$ X, ^( d0 j7 q- @
7 z! k9 X+ h5 ]; h. S% j5 n# o# e5 `
import java.util.Scanner ;
. S# a. f, P) m8 l' f! O9 [: {8 v+ U2 \1 t& ?1 S
public class j103
1 H9 _$ R  i# ?$ f# c$ i  Z! \1 t: U+ E6 Y
{
6 h5 ?. ]5 o9 h3 {% \$ E0 _
: ]- p  ^4 J; ~& l- C        public static void main(String[]arg)" h- u' K8 P9 s$ `5 I) W

& c! F6 }  {" B2 h        {
1 _9 d% b. `$ a% W; b' C" i5 t: E8 [: u% a* G# G: E$ [' `
        System.out.println("請輸入欲產生之亂數個數");
) Z+ e/ l: z6 p; a) ]* Q6 o; M6 S! ]7 q8 y. [. E
        Scanner s=new Scanner(System.in);. H. r. c1 E& `2 k# {* F

* o# u9 n% L+ R' w9 @% }3 y        //System.out.println(s.nextInt());7 p$ K: U# n; S  e  d1 J

6 [  X9 P3 r+ h/ G5 c. I# V! `        int n = s.nextInt();+ A7 i% @/ d' i2 m. ]# X

, Y7 p7 O% y6 _! D        int ar[]=new int[n];
! J$ }' [$ _' K# a5 m0 ]4 c+ s7 ]4 ]
                for(int i=0;i<n;i++)/ d) l- B* n1 `6 N1 D4 f2 h! ^; ~

6 P" c5 r' C# w( N7 x: c% a' G                {) \3 |* o' z+ v- M

3 Q% N7 ^6 ^, f: d' i. a$ ^  R, C& x2 s                ar[i]=(int)(Math.random()*1000);
, n9 K; C/ B! e' w$ K7 W4 E8 b+ {) \3 R4 k
                }
% t* L1 Y2 u1 }# R# g. f1 P1 M) p2 |4 ^6 q
        Arrays.sort(ar);
  R2 y2 }- e3 ~- Y4 Q
5 L) ~2 J: k5 z                for(int i=0;i<n;i++)
: {0 q; t' L5 x1 R. y! J/ ]5 [& A8 ^& d% M% v+ r% b5 t3 v) M
                {
2 A" T: o* |' ~9 f8 a
  g5 R3 @8 B. J9 J( [                System.out.print(ar[i]+"\n")        8 Y! x- H0 @5 q3 i" n5 L# S

5 o( g' C, x/ g$ V! y. Q) T               
; a4 e. U0 }  b, X  c' D- {" u4 o9 a! y  l
                }
! I5 Q9 w  \) U1 B
, _  J1 h" \. e& m- g        }
3 L  Q4 U. S; c$ m7 b. y  l9 O' B' L/ T4 m" R( N
}
人平

TOP

返回列表