返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 ; H' Q; [( V/ w0 P8 C- J# v
0 C0 c; {* ^% A& d+ T
程式中可以輸入值: I. r+ O8 _2 R- L& Q1 l) e8 [
0 a* U9 U$ S& c8 X8 G
實際寫出 jvd103
% O, l, p% t/ \  x' \% x- X" a: s. M( A1 V% u2 z! X) r/ n, g" 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 資料函式引入  j' a) n0 z* x2 ]) s4 r1 v
1 p  d5 q2 ?  N  Y
import java.util.Arrays ;+ Z  l, |) T2 z/ I
* r) Y; ~% u1 Z, u- o2 c

/ x" ]. j' q7 t5 R; K
7 n# P# s: H5 S. }5 F% ^6 mpublic class JVD103{
2 E: j  }8 I6 `8 N* p2 m/ R# l. \% }0 c' G9 ~7 H- V2 q

9 V7 }. p# o8 J- }0 A- {8 T. K/ A& b9 V; ~
        public static void main(String arg[]){) I! ^  f6 A) P6 j' M) p1 ^8 g0 V
+ _3 K% ~( `  ^; c4 t
        6 j8 c' `& P% o! j7 [

4 ]9 b& G; @4 `* b- A        
  u  k9 l2 @( y) g4 L) F1 b- H: l+ w
                System.out.println("請輸入欲產生之亂數個數:");6 u5 N& k" R* Q! n. A' J

: ?, q5 I7 O  M+ X        
4 L. O( q0 _4 V' V( S
% ~1 ^; }( T8 Y+ s: U% o                int n = 0;  //輸入要產生亂數個數 並初始化/ g/ J8 U# C% W9 D. S5 ^
0 a( f$ D- j" A5 e
               
8 o% s/ q! Q9 f4 b0 o3 U0 g" p) S( a: [( R) K. Q9 e
                //使用到io 一定要加上 try catch
0 o! J9 ^5 N% o3 K( B6 m  |5 S, d$ i6 O* q7 F% A
                try{. G9 e; _4 s4 m
6 z& N$ [0 H. E- u+ R' O
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
+ L8 I$ G; s. A- o" @2 v
9 u% N- d/ s' z) E6 ^. G                        BufferedReader br = new BufferedReader(isr); //資料暫存區
( t; C9 M3 h* x2 n7 c" m2 {- b$ K5 X8 N
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)/ d8 |. C  g6 K) c% \
- w& O8 o. ~; W
                }catch(Exception e){}. J: L! |' [0 W3 d

8 n/ q( Q& A' o! q2 j) U9 ]               
2 q0 S; J1 V1 ]$ N" J* t
8 b! J8 L% ?) q1 _/ S2 p9 ]                + `: @5 Z, {3 J
( Y0 p9 c2 i2 j
                int Num[] = new int[n];//產生n個亂數的變數$ K( X  B6 z, t
" ?5 U% ~5 }3 j0 t0 J% ?6 I2 c
                ' A/ a% N. E" i" q' Z
1 L  O. G( Y; v6 M% L1 r7 G
                for(int i=0;i<n;i++){- r9 ^6 A. o. f; j* R  a' K

# O  E0 u* {9 P8 |* Z4 g                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
3 x  {: K; ^7 F5 [4 `+ D4 ]) a; o0 ]1 M8 N& k0 l* D1 Z6 m
                        //System.out.println(Num[i]);! M% v9 l% a# L. M$ V9 _

4 `: A+ n) s" `& L& W& x) a; }. F8 t                }
: d% M9 w5 V* R. Q- i5 O* d$ _; m5 b+ {6 |5 D3 Q( i! h- e
                Arrays.sort(Num); //排序
7 `3 U" e) ~: i7 k0 K/ x4 }- ^3 i! l7 p! Z
                # P3 m$ `0 K7 a& Q
2 S) n6 h0 i: G2 E
                //輸出2 U+ _) l+ w. q
& O/ z+ H3 D8 o2 l" R) m( A
                for(int i=0;i<n;i++){, x1 r* C' k+ J. c

* K& p9 e7 X4 v) ?, i                   System.out.print(Num[i]+"\t");9 N* t6 T8 V) }  V7 N0 Y2 S) Y7 L  @

5 x4 m+ f6 `7 @) W/ Z# i                }" ^4 G& f$ }9 @: v; S$ N) x. r

& O5 o# F, ?& g5 s* k                ( g$ o  v/ t3 r, U* U- `3 w

$ C! h; P0 ^2 }- @0 [% j6 w        }
' a4 c1 a: r1 M; \9 f( R4 o3 i" u2 {8 {* l* I9 p
$ c9 U& d3 D; D; g+ F' ^
. Q1 V" D, e2 D+ o4 h$ t: A2 k& v7 [
}
人平

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;( H' `3 D1 C- `: {! \/ p: L# e
7 k5 h' o9 _% J, x: ?- @
import java.util.Scanner ;2 s1 {1 `* {) K! ^+ o
; G1 W9 |" z& W5 `0 L6 R
public class j103
; m6 A, e7 j, W. ?# ?4 `2 R6 H1 I- A: D" q( W* x
{
$ [  E2 Y6 U# L; A
* U- H- X2 V  }9 n$ |        public static void main(String[]arg)2 Z" r! U, Y% G+ K" B  g1 q

5 f7 J, b" ~7 C! G/ g6 t        {
5 n8 n8 t- \) o, ?! A7 R" y
( h8 v1 L% S, T# e' c( d+ w        System.out.println("請輸入欲產生之亂數個數");
! Y$ h9 \* B' r1 C
' p$ J6 z6 `4 Z* E) A: E) o+ N  c        Scanner s=new Scanner(System.in);
8 ]5 f- l7 I' Y$ i' @: t
2 O0 e3 q+ o2 P, y  ?% }; _- S        //System.out.println(s.nextInt());" l- p% o% `6 Z$ ?6 B& ]
& Q; V$ M1 h% O" M2 }- T
        int n = s.nextInt();8 ~: R: t: |& o* `) q

! w3 ^; ]' K, u% Q+ A& g  N) q        int ar[]=new int[n];* N" v( {8 y- J

1 s9 x7 ?4 o7 q3 ^                for(int i=0;i<n;i++)
, H; S  I, ~) X4 r6 F( }
! P7 w0 w# J- ^                {
) i  ]+ U2 w* t% u/ @! I
3 m. D+ X2 \4 W+ {; I2 N  e! a( n                ar[i]=(int)(Math.random()*1000);
3 t3 T: p. L8 Q2 h4 H3 i8 z
. f) `: ]' }' e2 U' ~8 l                }; s- T+ Q$ i! O. |6 g- W
5 q8 _2 @( t1 e
        Arrays.sort(ar);
! U. s; N; b% h% |
; Q$ O, C- u  Z* O0 B( I                for(int i=0;i<n;i++)% T" W4 X* W  {* N( O: D8 X% z
$ y! h. Y- e3 c2 p5 Y1 T4 F
                {
9 Y, K$ n" `# q5 f" P' j( U" T( b% J+ q6 O$ z
                System.out.print(ar[i]+"\n")        
/ c. _' U" j. Q* T5 M1 a: T% i# ^- w7 i- o6 ~, S% v% @
               
& j' V; ~( `( q
9 f/ B3 ]4 V5 h/ j7 Y                }& }1 {" k/ v8 D$ j: T2 f

) z; k0 \3 ^. z/ n2 ]8 ^# o        }
$ A" C$ h" ^+ F2 d/ x$ E) `" l) r( j1 K3 M
}
人平

TOP

返回列表