返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 5 p4 L' ^5 J+ N& n' N; Z, R! U

% {, ?0 Q+ l- V/ H% L0 f程式中可以輸入值9 y9 L( R. K! k& u
9 A8 u: V+ d0 J( k- p: c- K
實際寫出 jvd103- w; n: K! Q6 V& G5 C

! }, n6 z8 J0 F5 A) i1 v使用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 資料函式引入' ~. K! W5 O: U
8 y7 I. p; ]/ @( E
import java.util.Arrays ;
& q) J0 ]6 g$ J9 c- W" R
+ C6 H  T1 i. D! `, K6 f/ _) v$ w+ v1 b1 w3 L+ r# l; o) |

! o. U( M7 X' J4 Z8 Z. Y$ hpublic class JVD103{7 {2 s$ ?& Z: o. H: h& Q8 Q7 p) ?
. j1 b( S- R# U3 [8 J) I, N
) K: K9 y- ]) o8 f

4 Q1 X, @6 f, o  V- s        public static void main(String arg[]){! n" u1 ^& E4 b3 s: V& H( Z

7 M2 M2 _4 X1 h, c4 h3 V, K        ; o1 u3 |$ ^/ n3 A( f8 t

" y7 K( [' T8 [# c# S9 L        ! T* s7 Z8 [3 j7 U

7 _) G. o: |7 T- `5 j                System.out.println("請輸入欲產生之亂數個數:");
* `3 V1 v4 C- q2 M' u" W3 R# b1 x" O- W* ]* w* B: y. p( X; x
        
1 `! |, }1 E( {$ O; E7 {; L& T. _5 z7 D0 H! i$ @8 V: [$ U) I8 L
                int n = 0;  //輸入要產生亂數個數 並初始化1 Z9 a" D9 T, y8 a+ `: B

$ G& a2 L. y6 C# a0 P                ( I! {4 V/ v* B# z/ {; ~  Y

+ H, D- j4 @3 \3 {" u% S                //使用到io 一定要加上 try catch
* K. `9 x8 N0 I  D5 W$ n
7 A' c2 w9 p. P, ]                try{* Y) I: O% E5 |3 G+ Q* p6 i4 ^( u

! h$ y8 K! f: Y$ l$ ]                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
! V$ ]1 y3 t  e# d4 |. H0 P5 g/ c
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
9 c) w; S* F9 Z% O0 y
( ~- z6 T# ?- d                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
6 R) M* H" k, @+ l
4 r8 @! _; k3 o% }4 g/ U3 t                }catch(Exception e){}) P7 o) z' Z3 c# d6 O
- J6 K4 L3 g1 q. t
                : J: p4 a  R0 I' }1 x" E; P

1 S: R+ S7 r8 Z2 ~. ], b. S+ Y                % u7 a  n* \$ @

3 d; Q1 }0 n3 ?$ v0 R+ _2 i  k                int Num[] = new int[n];//產生n個亂數的變數
& d; r( P, f4 Z$ U. o6 s
5 \. ]( v( r: X* e                & L3 o# P! O: p( |+ A" @1 n" ^) R

& ]% J' \: m$ z/ D% C6 r0 o                for(int i=0;i<n;i++){9 _6 j4 _, b' ?- W2 u! F
, a7 s9 @( h) u
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int); C5 v7 |  L$ @! Z6 L7 Y

$ I1 m6 E- e; v3 v) Y                        //System.out.println(Num[i]);, m1 Y# ]6 _6 J! J3 }- ?
- C8 s& u# V' c4 U5 j
                }
! Z2 N, d! d4 I5 Q$ ?- A8 F$ m4 b  }7 }+ l* L7 ~: _
                Arrays.sort(Num); //排序. b$ }! [* N+ ]$ z. e$ h
" f# J/ A" o' r- D" N
                9 v+ O6 [; G! F
4 P6 a% ]0 |* a
                //輸出) S4 P% Q/ ?3 S9 G; \/ n

9 I9 a( x, c  K7 z6 N                for(int i=0;i<n;i++){0 Y; _6 o3 d3 Q; e0 V2 K7 H
& Y7 D( y$ D& g* \; P6 J
                   System.out.print(Num[i]+"\t");
' ^" J1 C- T2 B2 p$ K2 f9 @/ @1 G7 i
                }( u- }4 l* E  o5 J) ]
3 s8 @) l9 Z6 n6 P8 J
                * E8 z- |  o6 |% u- E& a
  \! f- _4 c& {" C% p' _! g2 h1 R( T
        }# w1 \5 X) n5 W# Z

: H3 h% D* a1 @/ y2 T$ r3 F3 ^6 D" o2 R" |
* C: B: m/ |# l3 l! K2 D' q
}
人平

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;* Q, G4 b+ s7 x0 b# a+ _& `
/ _! W4 B8 K. @4 w) z% b  d3 i6 j
import java.util.Scanner ;8 f* s& [8 v7 c
* |( ^6 G! R$ g3 U0 D+ F) V, L
public class j103
& ^, O6 N( P( z$ P3 m
8 |, a, K" @* s& r/ [{6 X  E0 {# w) s+ u

& F' i* s: z5 ?3 G9 q1 X( T3 i* X& \        public static void main(String[]arg)
9 M; V( p( m& h; t( R8 m7 a  ^2 w* D  C: y% I
        {
$ h+ V) X2 u2 Y4 p- e
; I) \# A4 }  a: d& f/ D4 r        System.out.println("請輸入欲產生之亂數個數");0 E1 f: U8 s. h% p, x1 P9 L# n

; F" ]" E/ y, E9 v4 k        Scanner s=new Scanner(System.in);
: Y' b1 T' R4 G- g( W
& w' W0 j& g& |9 ~/ }        //System.out.println(s.nextInt());. K. p1 l' y* b: }& c
1 n) g, G+ V: \' Z% p
        int n = s.nextInt();% O7 V( n* V' |$ p) }
. R) U+ _. D7 u
        int ar[]=new int[n];
" k8 p/ ^/ O1 p& H, Y
' k' G# e, C% H$ ^                for(int i=0;i<n;i++)& E" x" d" h$ D: }; ^: r9 _5 b( l4 T
6 l8 t1 g; E1 L
                {& k/ H. }5 ]! V- ]2 O  |, B, q2 K2 _

! j2 g* {3 P0 g! D$ P                ar[i]=(int)(Math.random()*1000);8 q$ d8 ~# }" I3 B; ]$ }
  T5 [. I$ A7 C5 Z% D
                }. i: x- c4 ^  ?4 {  k
9 C, k" Q, y' a+ U. G
        Arrays.sort(ar);
+ ]% F$ P1 s* j# Z  {$ [/ O6 L; L7 \- a) m/ ~- e
                for(int i=0;i<n;i++)- L8 w) C+ @' g8 ~9 U7 P
/ Z3 W& r4 ~8 J; }7 F1 u& f
                {2 b' \5 Q* Z% ^- u5 O( N9 g% O8 B2 l- b

2 D6 x4 w3 |; F5 p: D) ^                System.out.print(ar[i]+"\n")        6 w: i* J& _4 ]
$ s' r) q& G$ S
               
( {% r' O% I  o+ Q
- K, K+ c- F1 T' V                }
9 t) i% f7 d" z) F
/ Y* |" C' f, ~* f3 _+ w        }" O0 p8 a4 {4 _# l( ]' c
- a6 @" t% ]! P% F1 r: x2 C
}
人平

TOP

返回列表