返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
  P& W, b7 {# Z
$ N+ _9 n5 x" q$ a! p程式中可以輸入值
( I0 d2 |+ p4 I2 L
* ]9 |) P, g1 v& v實際寫出 jvd103# ?" G/ c4 _! w# y# ^

4 \: w) T5 i9 ]4 w' ~/ q使用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 資料函式引入, y. Y( z* g% f# n. ?* o1 C1 q

1 r2 C% b$ k2 {$ g9 |0 W& Pimport java.util.Arrays ;
- Z  G/ L2 h% {: U5 A; g# p# R* s
& D# u# J( P7 _# y  P. u

9 I3 L3 G9 {1 L. c/ A* R1 lpublic class JVD103{" X$ O+ A: J5 Y9 T6 [
3 ^7 e/ S3 _8 n3 y/ y5 K  x2 A
& S1 A% D6 c0 |5 v
& X( A+ Z% v( i" o5 g7 e
        public static void main(String arg[]){. E6 `- |$ V& y' ?/ }- A
5 d3 E0 h2 ]& r! x
        + S7 o$ g5 h( t! y! @" ?" f

# I6 w, M% O; B        
* ?" G- H- b" G; n  `( ~' H- q, s! g8 [/ a, _2 S1 b
                System.out.println("請輸入欲產生之亂數個數:");2 G4 E9 y8 j% c

+ C7 P1 L5 P" b! M/ g/ p        
* X' J  h& X# k& Z/ i; G1 F0 b* X
                int n = 0;  //輸入要產生亂數個數 並初始化
. r: G& k" X: M+ t1 B
( i0 R  u9 o# d: U6 F, ?1 ?                ! A! ], w% l( c2 I
* q: z7 Y' k8 q
                //使用到io 一定要加上 try catch0 C. h+ R; X( Y4 \$ P! f
2 \+ `2 _: F- o" t/ i0 z3 K
                try{' O" @8 E7 f$ `  R. t
) R* ~: ~' Z# ^+ ]$ N# c
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
% z9 L' N# Q7 s. r
/ }6 P2 q% I; A/ k( J                        BufferedReader br = new BufferedReader(isr); //資料暫存區' f: ~; I" n2 X: y( f3 e

# s+ w+ s4 U8 ?3 X) M) }$ V+ C4 X; n2 p3 k                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換); l  T1 [) q) Y7 u
6 ]: {( R; I4 I
                }catch(Exception e){}, w, b5 B2 _. ?) p) q3 ^  F+ v
3 B' X2 x( k' |5 E1 T. \' c" g& F" \
                . \% k+ Y  K7 x4 b! }& Y- d

: h4 S/ g5 D2 |& t4 X, x               
' e) |* B0 b% ?$ r
" ^: C8 K5 c3 R, j, N1 V                int Num[] = new int[n];//產生n個亂數的變數3 F9 L( Q" n) Z6 m

) X+ _. j; G7 d$ w                $ ]7 n3 s/ Q* t/ C- N9 M

- h" I& B) _  C# n5 S! k. A6 R) e4 f  l4 e                for(int i=0;i<n;i++){- Q  k, u: e# x, F8 X

  N, A0 w0 ]# S8 S) z9 W                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
: m) G+ ]* K& P" L5 |
# u# v/ A( u! _  }  ?6 z* M; u                        //System.out.println(Num[i]);; u, Y* I  `6 b1 v
! }3 v+ ~& P/ b1 Y* {" B0 U/ p6 Z
                }
& B# I8 k1 d* h. v
! ]3 G7 v$ G* c8 N% W  `                Arrays.sort(Num); //排序4 J1 L, d+ [7 _& o6 Y

9 }8 V0 w% l0 K                3 F) v0 K+ v' w' W: m) R; h, A

* n0 t- P' p  W9 B4 q  F                //輸出
, j! r, k# p+ v; B$ Y" u( }
2 T# o6 x0 K2 J$ q                for(int i=0;i<n;i++){
. m9 F: q4 Z  L- p# E$ u  f) k
( A/ U# h% D/ M9 V                   System.out.print(Num[i]+"\t");) ?" r* r* z1 k* P$ t/ G5 d
: c8 {/ |. f/ L0 I+ B
                }5 c4 H% ]! u1 }: y, f
% l; \, z; s; p* R* Y# n
                , v% V9 P2 I3 b- p+ w
4 t  z5 L( C& Z, ?) [
        }- V; [0 t8 E) d: _

- y- ^2 j% Q% X4 t! C/ X0 X5 z" X
9 W& R7 V: x3 m8 ]1 z0 V* l. s4 r: w% @7 [7 ?* T; i9 N3 U* s* f
}
人平

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;0 J! X( Y" U5 D, ~4 Q; E

* n& V, s+ d, }) aimport java.util.Scanner ;
5 D& T8 [2 {! ~# Q& S0 ^* o7 @% n4 t) c# }
public class j103
0 f1 \0 }* D$ X% V# o) B& [- S% S
{
9 ]5 P5 U) l$ K* ?, R
! l0 @" j: p' ]8 ]        public static void main(String[]arg)
% v  K& G) G( T* n! q) s( a* v3 B2 Q4 f( _7 ?  ~" [8 z6 P
        {
2 e0 K4 f; ]+ g  M
1 G( g+ U; W9 D* ]# T$ @4 D        System.out.println("請輸入欲產生之亂數個數");5 ~+ B$ ]. O' @. ~/ d
0 Q9 u5 T' E& c% e4 a
        Scanner s=new Scanner(System.in);
$ F* q$ i! J( m7 |* @# Q- Z" x# [" V. b: H; I! A* T$ ]; j
        //System.out.println(s.nextInt());, e1 d* \7 }$ n. G: E. N
% b5 y% L7 |* ^( m
        int n = s.nextInt();( W8 H  ?9 R: G8 ?
' ^. m8 S! x# S5 C; E
        int ar[]=new int[n];! V& W% z- Z0 M
) i6 g# W3 L7 o9 C9 J
                for(int i=0;i<n;i++)" `# [( H- g4 Q+ P* `- P

: x3 C* a5 u3 d' M                {
1 S3 }! h( H2 P+ R. ~3 M& t( G9 Y& T+ S7 ~+ p% T
                ar[i]=(int)(Math.random()*1000);5 S2 e6 u  L, A9 T

5 y" A) h2 ?/ C9 ?, q0 J6 P                }
0 U9 r$ S0 b* P9 G- z0 ]9 f! e) `" n! P& z8 O5 J
        Arrays.sort(ar);
9 l& `4 I( _* z+ w5 y1 H+ f6 {8 G, C$ n" J5 I0 Z+ d
                for(int i=0;i<n;i++): s4 f6 D. Z& U1 p4 P% X

$ b( ^. ^9 v& J                {
; }3 j) D. c* b, G3 F. o/ }4 \. G' W% a. N* C0 h5 E3 ?' b
                System.out.print(ar[i]+"\n")        . n# m8 p% N. V1 o* E
. {( p" e4 r) X6 B- A
                0 s+ d- d' F# ?' n

4 u) z/ r/ ]* c- `7 G                }  c6 @) A  S0 N5 k
2 r- {0 Q3 L/ K) s& r
        }* S$ Q) [7 F. \- n9 L3 x
2 ]. I" ^% W/ Y
}
人平

TOP

返回列表