返回列表 發帖

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

本帖最後由 b790113g 於 2011-12-31 09:54 編輯 # b0 h9 }, l; i
# m$ r+ M& ^- v% P9 V. ^+ a
程式中可以輸入值* m) w6 ^: j- l. W6 t% X1 K9 j
  ?% l7 ?4 a1 P* D
實際寫出 jvd103; n3 ^2 C! m( |8 |

& o" H0 D0 j# u& 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.util.Arrays;
8 {2 V% n: X( V6 e/ |. f
2 B, F) ]) q7 R1 w( R  v% f4 wimport java.util.Scanner ;; [0 M% r( m  z

2 K* o1 ?4 V6 y/ T& Npublic class j103
5 y( a) z& W: u6 i
/ v7 i( ?3 e# U' U+ f{
( [5 u& [+ S/ w) i( \* N
' i) W2 Y, C3 O9 y( \1 r! O        public static void main(String[]arg)' K9 E, ^9 J; S0 z! P% t! j
' e1 H/ l" X6 k' z" p7 i
        {- z+ ^) v3 J) S

* U( N' J8 w$ |2 H        System.out.println("請輸入欲產生之亂數個數");+ x4 x$ ~: v' I* a+ `: C( s

5 S! z$ P3 _1 g( p        Scanner s=new Scanner(System.in);" Y2 {9 l" }* l! ^7 M$ v3 _, u
: x0 [/ D1 p  R8 V
        //System.out.println(s.nextInt());
1 }2 }+ ~  u  S8 M; z, M
0 @, a$ s! k, [, g        int n = s.nextInt();
# q0 m/ f  Z+ g) U: f7 i& d8 l! x3 O1 ^  }
        int ar[]=new int[n];
; m& j! S/ I/ _. _- u* w$ Q: U' S0 h. b3 |7 B8 \
                for(int i=0;i<n;i++)
# @/ Z. r( J# t% r3 T& K% ~7 ~" n" E# d
                {
' z+ I, i) ~7 }! V+ R% c7 k
' a1 y% M* \% K3 A4 v) v                ar[i]=(int)(Math.random()*1000);  ~" a! L  {3 m0 B+ M
" ^* g1 i- ?" {: f, x# J3 ^
                }4 h+ R' B: Y& p! Y3 d
' z" r( `1 x4 V- ^3 Q$ [6 ~6 u
        Arrays.sort(ar);
7 V' P' O# ]! R" \% |+ {& C2 _: ?3 R8 r
                for(int i=0;i<n;i++)
, }( R) m2 {3 |. |+ T: Z
  _7 y6 g; b* k$ e' P                {- A- b- m+ C5 J) w! P. O7 W

% G& N  A9 [$ O                System.out.print(ar[i]+"\n")        : X  F' O# ~2 p. h4 k+ k" t- ]

* E9 Q* K, K; U; q; [9 Q- B+ ^                  H/ D: K/ f/ S9 W0 ^# q

. m# m# @- y9 ^4 ]2 Y( p6 H                }0 D4 B' Z6 N- Q5 f4 d3 g3 o) `: p

( z" U' V/ }3 ?3 o7 I/ L1 y6 u        }. q/ g' j0 T& n( U% q

) q. q7 D9 k( x2 r1 i, Z1 X2 H}
人平

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

  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.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.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.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.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

import java.io.* ; // input output 資料函式引入8 t# r) d8 P" V: [. T
4 h( X( ]( Y- m+ @/ g% c
import java.util.Arrays ;
0 A  Z5 u3 L( y, G; P: T  c
+ y/ v' {$ X$ X7 ?9 N' b7 C8 N9 G5 R7 @; a, r9 N8 A' h6 |
' o! H0 J2 [& }) b4 f, @9 C( P
public class JVD103{- f, M4 \  }- l$ k

# b7 t% y, X0 [6 Y& y9 l! [/ Q
# d% i  E! n- H  I
        public static void main(String arg[]){, w0 L1 b' O" ~9 H# [0 B1 {$ P
5 M. i  |8 w1 T: A9 F
        
, j! s8 {* O+ ?# P( z7 u
9 Y0 t+ x  y! j  Q- l        
! I. t# z! Q5 F1 B( {2 j# z$ g
* C9 p& n2 D% {" j6 ^                System.out.println("請輸入欲產生之亂數個數:");
" F2 Y( A) @4 ~% n
4 e+ |( t, H4 q6 ?6 z9 y  o- J        6 q. t* D; k. R: t9 E: _) \
4 `* Z: R1 x+ ?) ?2 s$ L1 W, c
                int n = 0;  //輸入要產生亂數個數 並初始化
: t; c) a! }7 ?9 h$ ~% }2 q6 [3 x, Z3 E7 \" U% l) a
                ' P3 x: n! @7 u4 S

# L  z1 b% w5 ]: R  E0 {3 S                //使用到io 一定要加上 try catch
2 \5 [( v; Z& S$ r- \% I% Y: I0 p" P2 p0 ^+ g
                try{4 j) ~7 C# J) ~2 g! d
" \5 c& m" [+ V) C
                        InputStreamReader isr = new InputStreamReader(System.in);  //輸入資料流5 p& j0 _1 [/ R5 B
8 t' p% `1 B8 i# g3 F: i. k
                        BufferedReader br = new BufferedReader(isr); //資料暫存區
  V/ @) |0 R! c, \+ J+ D- h8 b) B5 w
                        n = Integer.parseInt(br.readLine()); //輸入的資料是String  但我們要的n是int (轉換)
6 X7 x( N$ T% M0 f$ I1 b. F
* ^% {0 a- M# g, k                }catch(Exception e){}0 M% m4 E8 Q6 G, W% V0 Z% h

; K6 m- _- }! Q; Z( T' V               
1 c% k: k8 v" p$ z& p+ ]& Y3 i8 ]% O1 T0 E# _% u
                $ X" y  D, x) `
. r, |# J) j$ [- A/ r
                int Num[] = new int[n];//產生n個亂數的變數1 ~1 a" e- l, C: ~; C% s

' B* C2 s& ?' Y                ) R* P- _, x0 F
# G- Z; j1 V  g; Z2 H4 v! P
                for(int i=0;i<n;i++){* C( b) f- U9 a  u

" L% k/ E% p1 l! ]: S0 P                        Num[i] = (int)(Math.random()*1000) ; //double int 都是數值,差別在小數點 (int)- M7 e9 Z% b! _+ A
4 k  n/ p) G2 O6 V
                        //System.out.println(Num[i]);) E! W$ H* [: ?& A& f' b: j8 z' i: L# l

* y% m2 f" I8 c, d3 J( t3 T6 k                }
. T- S% f9 E6 s- [; w% L1 ?1 s, Q2 ]" s
                Arrays.sort(Num); //排序
  k9 U/ e7 N) h5 T2 B* ]4 [& C; Z& v! G
                6 r6 s+ |$ p+ o# S. {) y

  A% I6 t8 v- S+ x" L                //輸出; V6 L" m# f  {! z0 r7 j

; x& f- e8 d0 r: U                for(int i=0;i<n;i++){
  q) p1 O  R+ e0 Y6 v7 r1 _7 C. w4 q! K  T( f
                   System.out.print(Num[i]+"\t");) f! n7 u. c  Y6 h. n
% Y1 j. R/ K  P7 F
                }
0 q2 J* L- s; v' K8 `8 n( @: K
3 V7 ?. D5 D. U7 _7 q               
! b/ o% U+ H1 A1 O' {8 t* n& k; t+ _% c& V" R  G: d/ D
        }4 }' P5 z! B4 i4 \4 z
' `# Y, g. O  N

* K$ c/ a# Q% U# A. H  _0 L, ]; @" Z1 K" L! D
}
人平

TOP

返回列表