返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯
4 ^  [! W6 _9 I/ U2 \3 ~4 X0 l  i* }  b; j6 O* Q# `, t; k
程式中可以輸入值
5 X4 Q( G4 Y# U9 \. I/ i) K
. v! M; U7 ?( @9 z/ |9 {實際寫出 jvd103: L& }' W4 ]8 ]$ Z; I6 ]

3 w3 u# h" Q& K: F$ B0 Z: e  @使用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 資料函式引入
+ ~" h+ f" \8 L/ ^$ X; l
0 k: Q8 ?# @6 c8 h7 Z5 Z6 Dimport java.util.Arrays ;
( r4 o1 s  r8 `1 x' d/ k  n- t2 [) Y) e: P7 m- |2 D/ M0 ~& I. A: W, j

/ O4 n3 Z4 O8 [7 s& K/ h$ e, {' n0 |  n6 c! \
public class JVD103{% }. {6 b5 q! x# P0 ~. q
6 q. k/ n; t# U2 o  p
- k9 ^" n, }$ E; f

8 }: y$ l. z9 i( X5 S        public static void main(String arg[]){% i% f  ]) b: G# U5 S0 ]

$ }8 s8 w" z4 \0 R1 m        6 `& N" o, f0 T/ N1 {* o- q

/ v1 R! ~' X1 Z        ' ]5 W. J# K3 C& ?! v0 W
% x8 r: C% k. s/ C6 K! o
                System.out.println("請輸入欲產生之亂數個數:");, g& [- C1 g4 o% [
1 k) k7 b2 W+ L6 z
        . P) I* w3 o& r% D

7 c1 m  M) U9 ~  P2 S& ^+ b                int n = 0;  //輸入要產生亂數個數 並初始化
! q/ c2 }/ C+ F- d6 d
; H1 A  N7 X2 j               
0 }7 e% j$ [( Q- V  y+ P
* n* y' w$ \& M$ D' R2 W                //使用到io 一定要加上 try catch/ |2 L2 T2 W9 }& u6 n
. [5 k. M# i/ w5 R5 z% z1 G
                try{( o  _/ l, t; o* B

: [2 ^/ ^: ~4 @: g                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流
+ E* e. b% `2 H: k" Q* t0 O& q9 e* L6 a& J# R$ W
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
$ C( H5 _3 O  o- v/ [8 C" T( i0 {' Y2 C4 s7 _0 h! @
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)6 z! k. v! t' W3 B
/ t1 d1 U- d1 v1 U( H8 S& N# N
                }catch(Exception e){}: T0 c# q- ^. [4 Q

8 f7 q* N+ X5 t3 i8 [: W0 ]. V7 u               
/ n6 Q  l' [5 M0 ?, f  Y* ~4 Y5 `  V( F
               
: m, l) p! d# w& @3 H+ w! Q
/ k( ~" _' D1 H( `! ^                int Num[] = new int[n];//產生n個亂數的變數' v" W* Q8 N* T( O
5 W$ e  E7 o0 X8 ^
               
: t! z8 a1 @- s7 ]4 `& ?" z3 E: Y7 T1 R7 n
                for(int i=0;i<n;i++){
$ K  V8 j  c1 }5 m- h4 z, U( H) }
                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)# |1 Q7 _# v& k, N* T8 N
4 o: i, j7 V* v8 {9 U2 w- D
                        //System.out.println(Num[i]);
4 i+ s3 D1 }5 |& R0 r
3 b/ Z/ `! r/ {7 H                }
9 b* F6 @8 t+ T% ]& [4 T
* H' M5 @) O# y0 K$ x                Arrays.sort(Num); //排序6 f0 p& ]" c8 y/ n/ N

: Z" y& |8 s- u+ ^3 J+ g                  G0 |" S) F1 N5 Q3 X
; Y3 S' s( ^5 R: b' a
                //輸出6 l" E) K. ]( j# F

% I* P; m3 M1 e7 G2 e1 O4 b                for(int i=0;i<n;i++){
( b) _: @# H3 F' z  ?4 n4 ]
& [- ~/ v& l5 Q) j. V9 u                   System.out.print(Num[i]+"\t");% e$ O. M: p; N# a% A- \

; d5 C: L8 y% F+ w/ e# D3 _9 l) j                }7 b7 |# O4 O5 D& _; Y! j

* O5 Z- C# M* ?                9 _0 G) a" e9 |9 k/ u( n& ]

: W; W( v9 E5 u        }, l& V+ _/ X0 A" @
+ ~6 P# f! ?3 Z* n& Q2 g

. v* V: J+ t% h" Q- n0 {7 p" V' p! V4 f( _2 F% _+ f4 T
}
人平

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;. O3 X6 X2 f, v: t. {; y' [
8 t6 R0 [$ t3 I3 v; s' E* K! a
import java.util.Scanner ;
) @7 p- t% k3 T8 l1 s1 m8 ]9 n) F8 V/ R) F* s
public class j103
/ i! p" V' U) X8 f! b
3 u9 L4 }6 X7 e; a) U: H{: }! P5 ^7 |' r3 r: J

) Q6 ]2 H% M. D# y9 ~$ m7 I        public static void main(String[]arg)
; R  `8 G% C% v9 A' S/ v
1 G# l) F+ u$ e- l3 c2 p! m; r        {
' `  C# S, l' E: G5 V* R# d
7 g" a, Z8 s  d: s        System.out.println("請輸入欲產生之亂數個數");5 H7 A+ c% ]0 V" d$ F. Y

$ C2 n1 y0 F( o7 E* y+ @2 e0 F        Scanner s=new Scanner(System.in);
% ]  y( E" p1 R& t/ Z# U2 K. X7 a* h( z" _, E
        //System.out.println(s.nextInt());+ G2 N( x* m' w( [

9 b" B  o. @) e8 x; l4 S( _        int n = s.nextInt();
3 k' e% p1 Q( q# e% m6 n5 i8 ?2 b# B' W, n2 |
        int ar[]=new int[n];9 I$ q' d* v2 R/ d5 T9 [  B
5 P! E) c! g' [; q. ]. \
                for(int i=0;i<n;i++)
" K( s) I8 J* R& |3 A# f) u( P2 I4 w. G5 `
                {
' _0 t- t, G) c2 T. V6 B4 k: j. g, u% w5 y5 }1 B
                ar[i]=(int)(Math.random()*1000);
% p  t- b' _7 l
8 y9 q4 S7 M* |                }
& a0 B) H2 X* T7 X" p+ a" T* c+ n3 l8 b, N1 T4 E, r
        Arrays.sort(ar);; {7 {: O  ^  `9 J6 c# z
  \9 i3 K' ^4 M  ?' I2 D  l  D
                for(int i=0;i<n;i++)
! D* T; h; c, `5 s; A. x1 @# L9 s# A9 c/ ^9 f; Y$ C
                {
( Z& u* S) E# {* ?& X7 E! z: \( R* O1 Q) q! g3 N( l; i" D+ K
                System.out.print(ar[i]+"\n")        $ V, E( ?0 i+ @6 z* `" M! w
. y; {9 [: x! R) C
               
6 ?6 v+ V" Q9 _: o: ~: N/ a( k8 l  S' i% M, ?* i- }
                }' k+ X( Z! T+ c8 \3 L! \1 L; @

- @9 j$ {6 t# L' ]- @* a        }3 Z1 q% {( ~7 t2 {

! r# ^, A; V8 Q* M, g9 @}
人平

TOP

返回列表