返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
; B  W4 z7 m- K- q: m; h2 h1 O( U: T' A
; I$ ]- j: w. M- B: z+ C3 O' i$ `8 k0 Z1 r程式中可以輸入值
/ `$ b6 h6 j  y5 _( @) \
* B" A& V) ]5 `: J實際寫出 jvd103
  S- j! a1 W; W6 @1 A: Z0 Y8 K9 B) u! }- V* h/ D- @
使用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 資料函式引入0 c+ k2 O$ v) ]4 a! }1 ^; B% q

# D( w+ v3 ]* F1 B: Fimport java.util.Arrays ;# v# V7 V, g4 z" T$ |9 u- l
/ J7 b4 _3 ]5 S$ m$ `8 y$ G$ k
' F$ g+ P) w9 w% n

2 |3 t  E: ^( a6 h- Wpublic class JVD103{
9 ~: ]. V7 M: b. I
7 B4 R& m8 G" t8 Z
/ Q( T0 O$ q9 h; K( q
1 m; z3 l4 t1 H" C' _        public static void main(String arg[]){
/ r( |+ c6 m# t9 m4 k/ [) q% Z8 l- M) ?+ e' _$ F$ U
        , X) Y: l/ X& z: U6 _
& T$ U% N6 c- {0 v
        0 s; P4 s  }& G2 E

0 V3 o2 N7 ?( |5 {" b                System.out.println("請輸入欲產生之亂數個數:");( t- C: h6 D& l% O+ F0 J

6 D+ O8 `3 e, E7 G  o( w; A        1 Z8 i) D& U# U' y' L' M* |
6 D$ G, F- [2 S0 P7 f) V
                int n = 0;  //輸入要產生亂數個數 並初始化% R8 }1 ?; O6 X$ y; D

) k- T; z4 b, F' n               
3 Z( d" w# F3 d) C: G0 P6 T: M$ g6 i1 Y6 O* Z; W! |0 p
                //使用到io 一定要加上 try catch* x0 w# L  v$ `, Q3 f
. D- ~- A* t  T5 p% q' S4 s1 u( q
                try{1 X% p/ x: t' o3 N4 }" L

4 j7 Y2 n0 n2 K! H$ ~8 f% ~                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
. E9 W0 Q; p2 K1 y$ ^: |
9 @" E7 n" p+ o4 t9 U$ _- q                        BufferedReader br = new BufferedReader(isr); //資料暫存區# U) Q0 ]) S& ^7 n8 D0 d$ F

% f4 p1 P' `: B9 G4 i. q1 L                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
, _7 x/ j& T- E1 @' X# H1 |6 C  G, ?) s8 J
                }catch(Exception e){}1 s+ b7 }8 H. \2 I* \

' X# b, G$ e2 B; K3 I+ C4 ]                % m8 C% p! S8 o& J4 k

% ^2 F( D. e" h, o- |* {                  a$ ]0 f( C2 o/ [# Z

2 M5 [4 K3 S4 K1 O% [                int Num[] = new int[n];//產生n個亂數的變數
; C* w1 }: k/ d! D4 x, j! ]% V7 d4 l9 N; u3 E) u
                / Q0 y1 K, g3 S8 m

; V4 }8 I, h5 `9 k" B1 v+ D% O                for(int i=0;i<n;i++){) F& g; C! n$ [, H9 l
, W. K! s3 h& G( U
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)
5 X7 s. y$ t- ?5 `' o' W
# \2 p" ^. m9 X5 ~" G                        //System.out.println(Num[i]);- O+ q& ?( Z$ K. e, i. D

, o2 ?9 J4 U2 F. G                }
' f+ z- x/ t$ Q1 x! r2 t9 M$ @; @9 @- L" T1 h& P
                Arrays.sort(Num); //排序) ]! A5 O" F- h
9 {% n* u% v3 w6 i: e
                ; \  c$ \8 H. g' J0 v% I, l1 k9 Z4 w

, u9 s: b! q) Z( e+ T' E6 w4 X/ C                //輸出
$ j- \3 X- B& b8 w" T
& R# @/ {; W  ~. _+ i                for(int i=0;i<n;i++){
$ F, F% `  M. r: n. M$ o  x, I8 f) q2 |
                   System.out.print(Num[i]+"\t");5 I7 p7 D; B5 d2 J7 ]% u* q* ?

' v% @- R- m+ U6 t; q3 ]                }+ I& U2 ~0 x- U- h/ a
: m; D& e+ S* Q: M& i
               
# L  ^9 r+ O+ W/ D7 {) {! R+ C. M" P$ N$ g; [) l
        }. l4 o5 H6 N; p; o* N% n

* X1 ]$ f! }& V1 w; ?2 A/ E" o; t1 f/ h/ c7 ]. b9 ?

. U$ E  ?# L; X% X7 D) _$ 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/ a3 k+ G9 J( p! X7 M# A/ O, z0 ~* D2 y% s
import java.util.Scanner ;
1 D# E# |$ r. g- E" e
# c- O1 r3 ^* l7 k4 q  y+ y$ {public class j1030 V2 c6 A/ X9 }3 M0 T, g2 J# ^3 }
1 ]# T' T. d7 r9 i3 ]
{
" Y6 i6 o9 C$ V9 e; L
+ h& {% A, {" m) n# Z8 Z        public static void main(String[]arg)7 B3 Q- A6 z. D7 {

1 W! D3 H4 d; J7 k+ F8 T0 j        {
, S8 u5 h2 ?* d4 K2 ~0 M
& e7 x! p) B* d2 d) z        System.out.println("請輸入欲產生之亂數個數");
& d1 W8 r( y: Q" ~( H2 X8 K( b3 |  w( n2 t
        Scanner s=new Scanner(System.in);( v, ]3 @! `9 E# F4 z& Q

" B6 ?$ p: c1 U        //System.out.println(s.nextInt());
7 F$ V* C/ r7 }( r& n+ n+ a$ K6 t$ n, S
2 k/ d5 f6 ~* m        int n = s.nextInt();$ z' e. e4 \& x$ d7 ~8 L0 s
+ f3 h5 N4 I3 q' P: C. [
        int ar[]=new int[n];9 s, c, V5 G- S+ h
0 y8 n' P% i' }" {2 P# X
                for(int i=0;i<n;i++)
$ }0 G' i* w& o! z8 K  G
; [4 A4 S  l2 x' p) }0 L( M                {% F; K  I- Q" \
" u( T6 x+ O' |8 q  B4 ?
                ar[i]=(int)(Math.random()*1000);
$ q( H4 _/ I) x+ ^" _! E/ ]7 v2 W$ t
                }7 ^. x1 R! K- ^' {# r  g
6 T! v  ?7 F& \% E
        Arrays.sort(ar);9 q3 N+ y$ d5 N: T/ }: w0 M, w" i

0 A2 m3 R! d2 m( n, p+ ]                for(int i=0;i<n;i++)3 y# D" ]3 R' F7 U# Z
, o7 M) I8 [4 |- G
                {& I1 M* L1 }* B1 `  }3 C

% C+ K' E4 c' J: k+ z- Q# @                System.out.print(ar[i]+"\n")        " [% C$ x3 G. v
! S& v: Y/ W( I6 T0 L# u* D5 c% k, W
               
. {3 t" V. z. ?' `- i5 p/ i# G0 n
# i, o7 J: Z  o& o                }
4 f: ^- ]" L/ G4 _* {; Y, a" [# V1 s; q
        }
; k3 m# e) W' \# k% i; s* e/ ]" m1 D! }; d$ r8 m
}
人平

TOP

返回列表